How to read hexadecimal/bcd format as double floating values?

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

类别

Help CenterFile Exchange 中查找有关 Low-Level File I/O 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by