gpt4 book ai didi

java - 如何根据 IEEE-754 格式将十六进制值转换为单精度 float 以及 double float

转载 作者:行者123 更新时间:2023-12-01 19:17:33 26 4
gpt4 key购买 nike

有人可以告诉我如何根据java中的IEEE-754格式将十六进制字符串转换为其相应的单精度或 double float 吗?

例如:“4682E989”和“A4703D4A0B0B7441”

BR补充

最佳答案

参见Double.longbitsToDouble .

Returns the double value corresponding to a given bit representation. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "double format" bit layout.

您可以使用 Long.parseLong 从十六进制表示中获取 long new BigInteger(s, 16).longValue() (正如 Peter Lawrey 指出的那样)。 Long.parseLong 不会这样做,因为它在大于 2^63-1 的数字上失败。

关于java - 如何根据 IEEE-754 格式将十六进制值转换为单精度 float 以及 double float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5937262/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com