Java.lang Package Classes

Java Float - floatToIntBits() Method



The java.lang.Float.floatToIntBits() method returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout. It includes the following important points:

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

Syntax

public static int floatToIntBits(float value)

Parameters

value Specify a floating-point number.

Return Value

Returns the bits that represent the floating-point number.

Exception

NA.

Example:

In the example below, the java.lang.Float.floatToIntBits() method returns the bits which represents the given floating-point number.

import java.lang.*;

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

    //creating float value
    float x = 5.2f;
    float y = -5.2f;

    //printing the bit representing x
    System.out.print("floatToIntBits value of x is: ");
    System.out.println(Float.floatToIntBits(x)); 

    //printing the bit representing y
    System.out.print("floatToIntBits value of y is: "); 
    System.out.println(Float.floatToIntBits(y));
  }
}

The output of the above code will be:

floatToIntBits value of x is: 1084647014
floatToIntBits value of y is: -1062836634

❮ Java.lang - Float