convert double to binary format

68 次查看(过去 30 天)
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?

回答(2 个)

Walter Roberson
Walter Roberson 2014-1-31
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.

Dries billiet
Dries billiet 2014-1-31
I knew this one, but it gives a 0101 answer. I am actually looking for a conversion in the ascii form. for example, the result I get from the converion to a .bin file for the value 1050= fid = fopen('test.bin','w','ieee-be'); fwrite(fid, 1050, 'integer*4'); fclose(fid);
@h

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by