Java Double - toHexString() Method
The java.lang.Double.toHexString() method returns a hexadecimal string representation of the double argument. Some examples are shown below:
Floating-point Value | Hexadecimal String |
---|---|
1.0 | 0x1.0p0 |
-1.0 | -0x1.0p0 |
2.0 | 0x1.0p1 |
3.0 | 0x1.8p1 |
0.5 | 0x1.0p-1 |
0.25 | 0x1.0p-2 |
Double.MAX_VALUE | 00x1.fffffffffffffp1023 |
Minimum Normal Value | 0x1.0p-1022 |
Maximum Subnormal Value | 0x0.fffffffffffffp-1022 |
Double.MIN_VALUE | 0x0.0000000000001p-1022 |
Syntax
public static String toHexString(double d)
Parameters
d |
Specify the double to be converted. |
Return Value
Returns a hex string representation of the argument.
Exception
NA.
Example:
In the example below, the java.lang.Double.toHexString() method returns a hexadecimal string representing the given double argument.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating double values double x = 5.2; double y = -5.2; //printing the hexadecimal string for x System.out.print("Hexadecimal string for x is: " ); System.out.println(Double.toHexString(x)); //printing the hexadecimal string for y System.out.print("Hexadecimal string for y is: " ); System.out.println(Double.toHexString(y)); } }
The output of the above code will be:
Hexadecimal string for x is: 0x1.4cccccccccccdp2 Hexadecimal string for y is: -0x1.4cccccccccccdp2
❮ Java.lang - Double