Compartir a través de


Double.ToHexString(Double) Method

Definition

Returns a hexadecimal string representation of the double argument.

[Android.Runtime.Register("toHexString", "(D)Ljava/lang/String;", "")]
public static string ToHexString (double d);
[<Android.Runtime.Register("toHexString", "(D)Ljava/lang/String;", "")>]
static member ToHexString : double -> string

Parameters

d
Double

the double to be converted.

Returns

a hex string representation of the argument.

Attributes

Remarks

Returns a hexadecimal string representation of the double argument. All characters mentioned below are ASCII characters.

<ul> <li>If the argument is NaN, the result is the string "NaN". <li>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 '-' ('\u005Cu002D'); if the sign is positive, no sign character appears in the result. As for the magnitude m:

<ul> <li>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".

<li>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".

<li>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(int) Integer.toString on the exponent value.

<li>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.

</ul>

</ul>

<table class="striped"> <caption>Examples</caption> <thead> <tr><th scope="col">Floating-point Value</th><th scope="col">Hexadecimal String</th> </thead> <tbody style="text-align:right"> <tr><th scope="row">1.0</th> <td>0x1.0p0</td> <tr><th scope="row">-1.0</th> <td>-0x1.0p0</td> <tr><th scope="row">2.0</th> <td>0x1.0p1</td> <tr><th scope="row">3.0</th> <td>0x1.8p1</td> <tr><th scope="row">0.5</th> <td>0x1.0p-1</td> <tr><th scope="row">0.25</th> <td>0x1.0p-2</td> <tr><th scope="row">Double.MAX_VALUE</th> <td>0x1.fffffffffffffp1023</td> <tr><th scope="row">Minimum Normal Value</th> <td>0x1.0p-1022</td> <tr><th scope="row">Maximum Subnormal Value</th> <td>0x0.fffffffffffffp-1022</td> <tr><th scope="row">Double.MIN_VALUE</th> <td>0x0.0000000000001p-1022</td> </tbody> </table>

Added in 1.5.

Java documentation for java.lang.Double.toHexString(double).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to