hex2dec broken in R2020a?
27 次查看(过去 30 天)
显示 更早的评论
Hi! We used to be able to do the following, at least up to R2019a:
>> hex2dec('ad55cb92eef08aea93f27c40457f8835')
ans =
2.304019174741754e+38
Now we switched to R2020a, and I get:
>> hex2dec('ad55cb92eef08aea93f27c40457f8835')
Error using hex2dec
Hexadecimal text has too many digits for specified or implied type suffix.
...how can I achieve the old behavior?
Thanks in advance for any help!
P.S. In our particular application, we don't care about the precision of the conversion, as the hex input is actually a hash generated by DataHash(string).
1 个评论
回答(2 个)
Jan
2021-3-12
编辑:Jan
2021-3-12
hex2dec is much slower than sscanf(s, '%x'):
value = pow2([96, 64, 32, 0]) * sscanf(str, '%8x')
During the conversion to a double you reduce the precision from 128 to 53 bits. So it is enough to convert the first half:
value = pow2([96, 64]) * sscanf(str(1:16), '%8x')
0 个评论
Stephen23
2021-3-12
format long
str = 'ad55cb92eef08aea93f27c40457f8835';
val = hex2dec(str(01:16))*pow2(64) + hex2dec(str(17:32))
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!