convert double to binary format
49 views (last 30 days)
Show older comments
Hello,
I am currently working on a case and I would like to convert some numbers to the binary format. I can write them to a .bin file.
fid = fopen('test.bin','w','ieee-be');
fwrite(fid, 5, 'integer*4'); %5 is an example of the value that I would like to know the binary value of.
fclose(fid);
But actually I would like to be able to get this value in my workspace in stead of in a binfile.
For example when you convert an int to a double, you write:
X= double(y);
I would like to do the same, but then to binary.
Is this possible?
0 Comments
Answers (2)
Walter Roberson
on 31 Jan 2014
DoubleAsCharacters = char(typecast(YourDouble, 'uint8'));
Note: MATLAB does not store characters in ASCII form, which would involve using 8 bits per character. MATLAB uses 16 bits per character. In the above code I form one character (16 bits) for each byte (8 bits) of the binary representation of the double.
0 Comments
See Also
Categories
Find more on Large Files and Big Data 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!