java.lang.Double longBitsToDouble(long bits)

Syntax:

public static double longBitsToDouble(long bits)

Java Code Example :

This java example source code demonstrates the use of longBitsToDouble(long bits) method of Double class.

Some takeaways on the longBitsToDouble(long bits) 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.
  • If the argument is 0x7ff0000000000000L, the result is positive infinity.
  • If the argument is 0xfff0000000000000L, the result is negative infinity.
package com.javatutorialhq.java.examples;

import static java.lang.System.out;

/*
 * This example source code demonstrates the use of  
 * longBitsToDouble(long bits) method of Double class
 */

public class DoubleLongBitsToDouble {

	public static void main(String[] args) {
		
		long val1 = 54564561;
		long val2 = 0x7ff0000000000000L;
		long val3 = 0xfff0000000000000L;
		
		/* 
		 * test all the possible scenario
		 * on using the longBitsToDouble method
		 */		
		
		out.println(val1 + " in double="
				+ Double.longBitsToDouble(val1));
		out.println(val2 + " in double="
				+ Double.longBitsToDouble(val2));
		out.println(val3 + " in double="
				+ Double.longBitsToDouble(val3));
	
		
	}
}

Sample Output :

Running the above example source code will give the following output

54564561 in double=2.6958475E-316
9218868437227405312 in double=Infinity
-4503599627370496 in double=-Infinity

Suggested Reading List :

References :