The floatToIntBits() method in Float Class is a built-in function in java that returns a representation of the specified floating-point value according to the IEEE 754 floating-point “single format” bit layout.
public static int floatToIntBits(float val)
Parameter: The method accepts only one parameter val which specifies a floating-point number to be converted into integer bits.
Return Values: The function returns the integer bits that represent the floating-point number. Below are the special cases:
- If the argument is positive infinity, the result is 0x7f800000.
- If the argument is negative infinity, the result is 0xff800000.
- If the argument is NaN, the result is 0x7fc00000.
Below programs illustrates the use of Float.floatToIntBits() method:
1.5 in int bits: 1069547520
Infinity in int bits: 2139095040 -Infinity in int bits: -8388608 NaN in int bits: 2139095040
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.