Convert 4char to one double values

2 views (last 30 days)
Hi, I have some data in a byte(char) format that i want to convert to double format. Does anyone tell how to do this in matlab?
I have read the data in to a char, where every 4 characters should represent a double.
My data looks like this :
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ
Thanks in advance

Accepted Answer

Walter Roberson
Walter Roberson on 19 Jan 2012
There are multiple methods of doing the conversion, depending on the byte order that the numbers were stored in compared to the byte order your machine is using.
Are you certain that you want 4 characters to represent a double, not a single ? If double then is the data representation custom or is the data stored as a single but you want a double as output? That is, double is 64 bits which is 8 bytes and single is 4 bytes.
If your data is a multiple of 4 bytes and each byte was stored to an individual character (the usual), and your byte orders match, and the 4 bytes are in the format of a single, then:
double(typecast(uint8(Data), 'single'))
(But easier would be to read it from the file as numeric.)

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!