Converting Hex value to negative fractional decimal

Hello,
I am trying to convert the Hex value ('BF6E23F8').
I know that the answer should be (-0.93023634).
Please correct me if I am wrong, but I need to convert the Hex value to 2's complement binary, then to decimal?
I've attempted to use quite a few functions I've found online including hex2dec, Fr_bin2dec.
But I am hoping you can direct me towards the solution.
Thanks,
Ryan D'Souza

댓글 수: 2

Why do you know the answer for this particular example is -0.93023634? Do you have other example pairs you can post?
I know the answer for this example because the Hex values were converted by someone before I got my hands on it. But they were using another application and doing the conversion by hand, so I have no indication of what steps were used.
Sure, here are some more examples :
(Hex) --> (Decimal)
3CCCE6BD -> 0.025012368
BF6E158D -> -0.930016339
C1C63C18 -> -24.77934265

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

 채택된 답변

Guillaume
Guillaume 2015년 2월 5일
It looks like your hexadecimal values are the representation of a single precision IEEE 754 number, in little endian format.
hexvalues = ['BF6E23F8';'3CCCE6BD';'BF6E158D';'C1C63C18']
hexbits = uint32(hex2dec(hexvalues)); %convert hexadecimal to 32-bit integer representation
[~, ~, endianness] = computer;
if endianness == 'B'
hexbits = swapbytes(hexbits); %on a big-endian computer, switch endianness
end
hexassingle = typecast(hexbits, 'single') %cast from integer to single

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Scripts에 대해 자세히 알아보기

질문:

2015년 2월 4일

댓글:

2015년 2월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by