Java.lang Package Classes

Java Float - floatToRawIntBits() Method

The java.lang.Float.floatToRawIntBits() method returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout, preserving Not-a-Number (NaN) values. 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 the integer representing the actual NaN value. Unlike the floatToIntBits method, floatToRawIntBits does not collapse all the bit patterns encoding a NaN to a single "canonical" NaN value.


public static int floatToRawIntBits(float value)


value Specify a floating-point number.

Return Value

Returns the bits that represent the floating-point number.




In the example below, the java.lang.Float.floatToRawIntBits() 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("floatToRawIntBits value of x is: ");

    //printing the bit representing y
    System.out.print("floatToRawIntBits value of y is: "); 

The output of the above code will be:

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

❮ Java.lang - Float