Convert 32 bit HEX to signed floating point

조회 수: 47 (최근 30일)
antlhem
antlhem 2017년 11월 1일
댓글: Walter Roberson 2022년 11월 30일
So far I use the function hexsingle2num to convert a double type number (i.e. 41c1999a = 24.200000762939453) but when I want to use the same to convert ffffffff it gives me NaN, then I have to manually use nhex2dec('ffffffff',32) = -1 (correct answer),same with another example C0728F5C = -3.79. What I am looking for is a way to automatise this process since I have thousands of values. Is there a function in matlab that includes the conversion of HEX to SIGNED floating point?

채택된 답변

Maitreyee Mordekar
Maitreyee Mordekar 2017년 11월 13일
편집: KSSV 2019년 12월 10일
Hi,
By hexsingle2num function I assume that you are referring to the following File Exchange submission: https://www.mathworks.com/matlabcentral/fileexchange/6927-hexsingle2num
This is one of the several submissions in MATLAB File Exchange on MATLAB Central which is a forum for our product users to interact, exchange information and knowledge, without MathWorks' involvement. You may contact the author of this submission directly for specific questions about the implementation.
However, you can obtain the same results using the following function:
typecast(uint32(hex2dec('C0728F5C')),'single')
Also, if you still need a way to convert hexstring to double precision number then you can consider using hex2num: https://www.mathworks.com/help/matlab/ref/hex2num.html
Hope that helps!
  댓글 수: 5
Badr Sahib
Badr Sahib 2022년 11월 30일
Hi,
can you please rearrange your command so that i give -3.79 and i can get 'C0728F5C'.
Walter Roberson
Walter Roberson 2022년 11월 30일
num2hex(single(-3.79))

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by