How to read hexadecimal/bcd format as double floating values?
1 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2020-11-10
回答: MathWorks Support Team
2021-2-1
I have some data stored in BCD format that I want to read directly as a floating-point value. How can I achieve this?
采纳的回答
MathWorks Support Team
2020-11-10
To achieve this, please follow the steps below:
1) Create a file with 'FF' written in BCD format:
str = ['FF'];
fileID = fopen('bcd.bin','w');
fwrite(fileID,hex2dec(str),'ubit16');
fclose(fileID);
2) First open the file and then read the data from that file:
fileID = fopen('bcd.bin');
onebyte = fread(fileID,1,'*ubit16')
3) You will see that "onebyte" is a variable of type "uint16" with a value of 255. To turn this into a MATLAB double, we can use the "double" function:
sol = double(onebyte) % this is 255.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Low-Level File I/O 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!