convert double to binary format
49 次查看(过去 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?
0 个评论
回答(2 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Large Files and Big Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!