120
Java Float toHexString() Method
The toHexString() method of Java Float class returns a hexadecimal string corresponding to the argument passed(float argument).
The result is:
- String “NaN”, if the argument passed is NaN.
- String representing sign and absolute value (magnitude) of the float parameter.
Syntax:
Parameters:
f – This is the float argument to be converted.
Return Value:
The toHexString() method returns a hex string illustration of the float argument.
Example 1
Output:
1. Hex String = 0x1.dd8654p22 2. Hex String = -0x1.9e66fp22 3. Hex String = 0x1.f9f7f8p-1
Example 2
Output:
1. 1.4E-45 converted to HexString = 0x0.000002p-126 2. 3.4028235E38 converted to HexString = 0x1.fffffep127 3. NaN converted to HexString = NaN 4. Infinity converted to HexString = Infinity 5. -Infinity converted to HexString = -Infinity
Example 3
Output:
Error:(5, 37) java: incompatible types: java.lang.String cannot be converted to java.lang.Float
Next TopicJava Float