Java - Double longBitsToDouble(long) method
Description
The Java Double longBitsToDouble() method returns the double value corresponding to a given bit representation. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point "double format" bit layout.It includes the following important points −
- If the argument is 0x7ff0000000000000L, the result is positive infinity.
- If the argument is 0xfff0000000000000L, the result is negative infinity.
Declaration
Following is the declaration for java.lang.Double.longBitsToDouble() method
public static double longBitsToDouble(long bits)
Parameters
bits − This is any long integer.
Return Value
This method returns the double floating-point value with the same bit pattern.
Exception
NA
Getting Double from long Example
The following example shows the usage of Double longBitsToDouble() method to get a double value from a given bit representation. We've printed three double values based on given bit representations.
package com.tutorialspoint;
public class DoubleDemo {
public static void main(String[] args) {
/* returns the double value corresponding to a given bit representation */
System.out.println(Double.longBitsToDouble(6757689L));
System.out.println(Double.longBitsToDouble(0x7ff0000000000000L));
System.out.println(Double.longBitsToDouble(0xfff0000000000000L));
}
}
Output
Let us compile and run the above program, this will produce the following result −
3.338742E-317 Infinity -Infinity
Getting Double from Positive long Example
The following example shows another usage of Double longBitsToDouble() method to get a double value from a given bit representation. We've printed a double value based on given bit representation.
package com.tutorialspoint;
public class DoubleDemo {
public static void main(String[] args) {
/* returns the double value corresponding to a given bit representation */
System.out.println(Double.longBitsToDouble(4624802752342104474L));
}
}
Output
Let us compile and run the above program, this will produce the following result −
15.3
Getting Double from Negative long Example
The following example shows the usage of Double longBitsToDouble() method to get a double value from a given bit representation. We've printed a double value based on given bit representation.
package com.tutorialspoint;
public class DoubleDemo {
public static void main(String[] args) {
/* returns the double value corresponding to a given bit representation */
System.out.println(Double.longBitsToDouble(-4598569284512671334L));
}
}
Output
Let us compile and run the above program, this will produce the following result −
-15.3