Java Double doubleToLongBits() method

The doubleToLongBits() method of Java Double class returns a floating-point value according to the IEEE 754 floating-point "double format" bit layout.

Syntax

Parameters

Value is the double parameter passed which is a double precision floating-point number.

Return value

The doubleToLongBits(double value) method returns the bits that represent the floating-point number.

  • If the argument is positive infinity, the result returned is 0x7ff0000000000000L.
  • If the argument is negative infinity, the result returned is 0xfff0000000000000L.
  • If the argument is NaN, the result returned is 0x7ff8000000000000L.

Example 1

Output:

5.5 value in long bits = 4617878467915022336
NaN value in long bits =9221120237041090560
Infinity value in long bits =9218868437227405312
-Infinity value in long bits=-4503599627370496

Example 2

Output:

-6.58768566756756E7 value in long bits = -4499261384967075684

Example 3

Output:

Error:(13, 43) java: incompatible types: long cannot be converted to java.lang.Double

Here, we are converting it into long bits and then putting it into double without an explicit cast. Either we should put it into long or should directly call this method in println function otherwise, you will get an error.