public static String toHexString (double d)

Returns a hexadecimal string representation of the
` double`

argument. All characters mentioned below
are ASCII characters.

- If the argument is NaN, the result is the string
"
`NaN`

". - Otherwise, the result is a string that represents the sign
and magnitude of the argument. If the sign is negative, the
first character of the result is '
`-`

' (`'\u002D'`

); if the sign is positive, no sign character appears in the result. As for the magnitude*m*:- If
*m*is infinity, it is represented by the string`"Infinity"`

; thus, positive infinity produces the result`"Infinity"`

and negative infinity produces the result`"-Infinity"`

. - If
*m*is zero, it is represented by the string`"0x0.0p0"`

; thus, negative zero produces the result`"-0x0.0p0"`

and positive zero produces the result`"0x0.0p0"`

. - If
*m*is a`double`

value with a normalized representation, substrings are used to represent the significand and exponent fields. The significand is represented by the characters`"0x1."`

followed by a lowercase hexadecimal representation of the rest of the significand as a fraction. Trailing zeros in the hexadecimal representation are removed unless all the digits are zero, in which case a single zero is used. Next, the exponent is represented by`"p"`

followed by a decimal string of the unbiased exponent as if produced by a call to`Integer.toString`

on the exponent value. - If
*m*is a`double`

value with a subnormal representation, the significand is represented by the characters`"0x0."`

followed by a hexadecimal representation of the rest of the significand as a fraction. Trailing zeros in the hexadecimal representation are removed. Next, the exponent is represented by`"p-1022"`

. Note that there must be at least one nonzero digit in a subnormal significand.

- If

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` |

`d` | the ` double` to be converted. |

Diagram: Number