Java - 将十六进制转换为 IEEE-754 64 位浮点数 - 双精度 [英] Java - Convert hex to IEEE-754 64-bit float - double precision
问题描述
我正在尝试将以下十六进制字符串:41630D54FFF68872"转换为 9988776.0 (float-64).
I'm trying to convert the following hex string: "41630D54FFF68872" to 9988776.0 (float-64).
使用单精度 float-32 我会这样做:
With a single precision float-32 I would do:
int intBits = Long.valueOf("hexFloat32", 16).intValue();
float floatValue = Float.intBitsToFloat(intBits);
但是当使用上面的 64 位十六进制时,这会抛出一个:java.lang.NumberFormatException: Infinite or NaN.
but this throws a: java.lang.NumberFormatException: Infinite or NaN when using the 64-bits hex above.
如何将十六进制转换为使用 IEEE-754 编码的 64 位双精度浮点数?
How do I convert a hex to a double precision float encoded with IEEE-754 with 64 bits?
谢谢
推荐答案
你想要双精度,所以 Float 不是正确的类 - 那是单精度的.
You want double-precision, so Float isn't the right class - that's for single precision.
相反,您需要 Double 类,特别是 Double.longBitsToDouble.
Instead, you want the Double class, specifically Double.longBitsToDouble.
这篇关于Java - 将十六进制转换为 IEEE-754 64 位浮点数 - 双精度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!