Java floating-point numbers representation as a hexadecimal numbers

前端 未结 2 850
鱼传尺愫
鱼传尺愫 2020-12-10 14:32

Why does 0x1p3 equal 8.0? Why does 0x1e3 equal 483, whereas 0x1e3d equals 7741? It is confusing

相关标签:
2条回答
  • 2020-12-10 15:30

    0x1e3 and 0x1e3d are hexadecimal integer literals. Note that e and d are hexadecimal digits, not the exponent indicator or double type indicator in this case.

    1e3d is a decimal floating-point literal. The e is the exponent indicator, the d says that this is a double rather than a float.

    The notation 0x1p3 is a way to express a floating-point literal in hexadecimal, as you can read in section 3.10.2 of the Java Language Specification. It means 1 times 2 to the power 3; the exponent is binary (so, it's 2-to-the-power instead of 10-to-the-power).

    0 讨论(0)
  • 2020-12-10 15:35

    0x1e3 is hex for 483, as is 0x1e3d hex for 7741. The e is being read as a hex digit with value 14.

    0 讨论(0)
提交回复
热议问题