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!