gpt4 book ai didi

java - 无法理解 java 中 Float.toHexString() 方法的 o/p

转载 作者:搜寻专家 更新时间:2023-11-01 02:45:23 25 4
gpt4 key购买 nike

我想知道如何得到 float 的十六进制表示。 我尝试了以下代码

      System.out.println(Float.toHexString(56)); 

知道了/p

  0x1.cp5 

我真的不明白。如果我使用 Integer 方法,o/p 将是 38,我可以理解...但是 o/p 是如何出现的 0x1.cp5。任何人都可以告诉我或指出一些好的教程..在此先感谢。

最佳答案

引用java.lang.Float javadocs:

http://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#toHexString%28float%29

  • If m is a float value with a normalized representation, substrings are used to represent the significand and exponent fields. The significand is represented by the characters "0x1." followed by a lowercase hexadecimal representation of the rest of the significand as a fraction. Trailing zeros in the hexadecimal representation are removed unless all the digits are zero, in which case a single zero is used. Next, the exponent is represented by "p" followed by a decimal string of the unbiased exponent as if produced by a call to Integer.toString on the exponent value.
  • If m is a float value with a subnormal representation, the significand is represented by the characters "0x0." followed by a hexadecimal representation of the rest of the significand as a fraction. Trailing zeros in the hexadecimal representation are removed. Next, the exponent is represented by "p-126". Note that there must be at least one nonzero digit in a subnormal significand.

关于java - 无法理解 java 中 Float.toHexString() 方法的 o/p,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23358735/

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