Java.lang Package Classes

Java Double - doubleToLongBits() Method



The java.lang.Double.doubleToLongBits() method returns a representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout. It includes the following important points:

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

Syntax

public static long doubleToLongBits(double value)

Parameters

value Specify a double precision floating-point number.

Return Value

Returns the bits that represent the floating-point number.

Exception

NA.

Example:

In the example below, the java.lang.Double.doubleToLongBits() method returns the bits that represent the given floating-point number.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {

    //creating double values
    double x = 25;
    double y = -25;

    //printing the bit which represents x
    System.out.print("doubleToLongBits value of x is: ");
    System.out.println(Double.doubleToLongBits(x)); 

    //printing the bit which represents y
    System.out.print("doubleToLongBits value of y is: "); 
    System.out.println(Double.doubleToLongBits(y));
  }
}

The output of the above code will be:

doubleToLongBits value of x is: 4627730092099895296
doubleToLongBits value of y is: -4595641944754880512

❮ Java.lang - Double