繁体   English   中英

如何根据 IEEE-754 格式将十六进制值转换为单精度浮点数以及双精度浮点数

[英]How to convert hex value to single precision floating point number and also in double precision floating point number according to the IEEE-754 format

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

例如:“4682E989”和“A4703D4A0B0B7441”

BR 供应商

请参阅Double.longbitsToDouble

返回与给定位表示对应的双精度值。 根据 IEEE 754 浮点“双格式”位布局,该参数被视为浮点值的表示。

你可以从十六进制表示中得到一个longLong.parseLong new BigInteger(s, 16).longValue() (正如 Peter Lawrey 指出的那样)。 Long.parseLong不会做,因为它在大于 2^63-1 的数字上失败。

这是正确答案的示例。

十六进制值 = 440B1831

预期二进制 = 1000100000010110001100000110001

预期浮动= 556.378

  Long decimal  =new BigInteger("440B1831", 16).longValue();
   String binary1 = java.lang.Long.toBinaryString(decimal);
    System.out.println(binary1);
     int intBits = Integer.parseInt(binary1, 2);
    float myFloat = Float.intBitsToFloat(intBits);
   System.out.println( myFloat);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM