フィルターのクリア

hex2dec broken in R2020a?

27 ビュー (過去 30 日間)
Jorge
Jorge 2021 年 3 月 12 日
編集済み: Jan 2021 年 3 月 12 日
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 件のコメント
Jan
Jan 2021 年 3 月 12 日
編集済み: Jan 2021 年 3 月 12 日
Do you have a good reason to convert the hash to a decimal value? I cannot imagine how this could be useful. The has contains 128 bits, but a double value only 53.

サインインしてコメントする。

回答 (2 件)

Jan
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')

Stephen23
Stephen23 2021 年 3 月 12 日
format long
str = 'ad55cb92eef08aea93f27c40457f8835';
val = hex2dec(str(01:16))*pow2(64) + hex2dec(str(17:32))
Warning: Hexadecimal numbers representing integers greater than or equal to flintmax might not be represented exactly as double-precision floating-point values.
Warning: Hexadecimal numbers representing integers greater than or equal to flintmax might not be represented exactly as double-precision floating-point values.
val =
2.304019174741754e+38

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by