convert double to binary format

63 visualizaciones (últimos 30 días)
Dries billiet
Dries billiet el 31 de En. de 2014
Respondida: Walter Roberson el 31 de En. de 2014
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?

Respuestas (2)

Walter Roberson
Walter Roberson el 31 de En. de 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.

Dries billiet
Dries billiet el 31 de En. de 2014
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

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by