Java.lang Package Classes

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 ValueHexadecimal String
1.00x1.0p0
-1.0-0x1.0p0
2.00x1.0p1
3.00x1.8p1
0.50x1.0p-1
0.250x1.0p-2
Double.MAX_VALUE00x1.fffffffffffffp1023
Minimum Normal Value0x1.0p-1022
Maximum Subnormal Value0x0.fffffffffffffp-1022
Double.MIN_VALUE0x0.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