How do I convert from HEX to DEC numbers larger than 2^52?
조회 수: 13 (최근 30일)
이전 댓글 표시
MathWorks Support Team
2014년 8월 14일
편집: MathWorks Support Team
2023년 11월 22일
The MATLAB function "hex2dec" has a input limit of 2^52, how do you convert numbers larger than 2^52 from HEX to DEC in MATLAB?
채택된 답변
MathWorks Support Team
2023년 9월 21일
편집: MathWorks Support Team
2023년 11월 22일
If the input is greater than 2^52 but smaller than 2^64, consider one of the two options described in the documentation below::
https://www.mathworks.com/help/matlab/ref/hex2dec.html#f72-104326_sep_mw_8a537ff9-c24e-4f07-8539-a5530fa994f8
If the input is greater than or equal to 2^64, you will need to use the Symbolic Toolbox. Please refer to the following example in the documentation for the full workflow:Convert Hexadecimal and Binary Values to Symbolic Decimal Numbers
Below is a simple example code for the workflow:
>> H='0xffffffffffffffffffffffff';
>> D = str2sym(H)
D =
79228162514264337593543950335
댓글 수: 1
추가 답변 (1개)
Walter Roberson
2023년 8월 11일
If the number is larger than 2^52 then if it is an integer it needs to be either int64 or uint64.
H = '400921fb54442d18';
D = sscanf(H, '%lx')
dec2hex(D)
num2hex(pi)
Dd = typecast(D, 'double')
Dd - pi
We see we bit-for-bit reconstruction
If the value is intended to be int64 instead of uint64, then use the %lx format to get uint64 and then typecast() that to int64
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!