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!