Float.toHexString() in Java

Float.toHexString(): This method is available in java.lang.Float class of Java.

Syntax:

String java.lang.Float.toHexString(float f)

This method takes one argument of type float as its parameter. This method returns a hexadecimal string representation of the float argument.

Note:

1. If the argument is NaN, the result is the string"NaN".

2. Otherwise, the result is a string that represents the sign and magnitude (absolute value) of the argument.

Parameters: One parameter is required for this method.

f: the float to be converted.

Returns: a hex string representation of the argument.

For Example:

float f = 19919.6f

Float.toHexString(f) = > It returns 0x1.373e66p14

Approach

Java

public class FloattoHexString {
    public static void main(String[] args) {

        float f = 19919.6f;
        System.out.println(Float.toHexString(f));

    }
}

Output:

0x1.373e66p14

No comments:

Post a Comment