I don’t understand the difference between hex2dec and hex2num and their opposites in MATLAB.
Say I had a hex value, 3FD3B502C055FE00. When I use hex2dec, I get 4.5992e+018
. When I use hex2num, I get 0.3079. What’s going on?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
These functions work very differently, as you noticed.
hex2decconverts a hexadecimal string to a floating-point number by raw byte conversion, and I think you found that this works as you were expecting. However,hex2numconverts a hexadecimal string to its IEEE double-precision representation.The IEEE 754 double precision standard calls for a one-bit sign, a 11-bit exponent, and a 52-bit fraction. So
hex2numparses the hexadecimal in this format, yielding a very different result fromhex2dec.