How to read hexadecimal/bcd format as double floating values?
조회 수: 4 (최근 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!