Float.ToHexString(Single) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a hexadecimal string representation of the
float
argument.
[Android.Runtime.Register("toHexString", "(F)Ljava/lang/String;", "")]
public static string ToHexString (float f);
[<Android.Runtime.Register("toHexString", "(F)Ljava/lang/String;", "")>]
static member ToHexString : single -> string
Parameters
- f
- Single
the float
to be converted.
Returns
a hex string representation of the argument.
- Attributes
Remarks
Returns a hexadecimal string representation of the float
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 (absolute value) 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 float
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 float
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-126"
. 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> <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">Float.MAX_VALUE
</th> <td>0x1.fffffep127
</td> <tr><th scope="row">Minimum Normal Value
</th> <td>0x1.0p-126
</td> <tr><th scope="row">Maximum Subnormal Value
</th> <td>0x0.fffffep-126
</td> <tr><th scope="row">Float.MIN_VALUE
</th> <td>0x0.000002p-126
</td> </tbody> </table>
Added in 1.5.
Java documentation for java.lang.Float.toHexString(float)
.
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.