- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java - Double toHexString() method
Description
The Java Double toHexString() method returns a hexadecimal string representation of the double argument d.Some examples can be seen here −
| 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 | 0x1.fffffffffffffp1023 |
| Minimum Normal Value | 0x1.0p-1022 |
| Maximum Subnormal Value | 0x0.fffffffffffffp-1022 |
| Double.MIN_VALUE | 0x0.0000000000001p-1022 |
Declaration
Following is the declaration for java.lang.Double.toHexString() method
public static String toHexString(double d)
Parameters
d − This is the double to be converted.
Return Value
This method returns a hex string representation of the argument.
Exception
NA
Getting Hexadecimal String Representation of a Double Object Example
The following example shows the usage of Double toHexString(double) method to get a hex string representation of a double. We're showing multiple hex representation of positive double values along with hex representation of max double value.
package com.tutorialspoint;
public class DoubleDemo {
public static void main(String[] args) {
/* returns a hexadecimal string representation of the
double argument */
String str = Double.toHexString(1.0);
System.out.println("Hex String = " + str);
str = Double.toHexString(3.0);
System.out.println("Hex String = " + str);
str = Double.toHexString(0.25);
System.out.println("Hex String = " + str);
str = Double.toHexString(Double.MAX_VALUE);
System.out.println("Hex String = " + str);
}
}
Output
Let us compile and run the above program, this will produce the following result −
Hex String = 0x1.0p0 Hex String = 0x1.8p1 Hex String = 0x1.0p-2 Hex String = 0x1.fffffffffffffp1023
Getting Hexadecimal String Representation of a Double Object With Negative Value Example
The following example shows the usage of Double toHexString(double) method to get a hex string representation of a double. We're showing multiple hex representation of negative double values along with hex representation of min double value.
package com.tutorialspoint;
public class DoubleDemo {
public static void main(String[] args) {
/* returns a hexadecimal string representation of the
double argument */
String str = Double.toHexString(-1.0);
System.out.println("Hex String = " + str);
str = Double.toHexString(-3.0);
System.out.println("Hex String = " + str);
str = Double.toHexString(-0.25);
System.out.println("Hex String = " + str);
str = Double.toHexString(Double.MIN_VALUE);
System.out.println("Hex String = " + str);
}
}
Output
Let us compile and run the above program, this will produce the following result −
Hex String = -0x1.0p0 Hex String = -0x1.8p1 Hex String = -0x1.0p-2 Hex String = 0x0.0000000000001p-1022
Getting Hexadecimal String Representation of a Double Object With Negative Zero Value Example
The following example shows the usage of Double toHexString(double) method to get a hex string representation of a double. We're showing multiple hex representation of negative and positive zero values.
package com.tutorialspoint;
public class DoubleDemo {
public static void main(String[] args) {
/* returns a hexadecimal string representation of the
double argument */
String str = Double.toHexString(-0.0);
System.out.println("Hex String = " + str);
str = Double.toHexString(0.0);
System.out.println("Hex String = " + str);
}
}
Output
Let us compile and run the above program, this will produce the following result −
Hex String = -0x0.0p0 Hex String = 0x0.0p0