Java Float floatToRawIntBits() methodThe floatToRawIntBits() method of Java Float class returns the specified floating-point value according to the IEEE 754 floating-point 'single format' bit layout. Syntax:Parameters:A float type parameter (value) is passed. Here value is a floating-point number. Return Value:The floatToRawIntBits(float value) method of Float class returns the bits of the given floating-point number.
Example 1Test it NowOutput: 9.8 value in Raw int bits = 1092406477 NaN value in Raw int bits = 2143289344 Infinity value in Raw int bits = 2139095040 -Infinity value in Raw int bits = -8388608 Example 2Test it NowOutput: -658756.56value in Raw long bits = -920595383 -6547.6577 value in Raw long bits = -976446141 Example 3Test it NowOutput: Error:(14, 42) java: incompatible types: int cannot be converted to java.lang.Float Here, we are converting it into int bits and then putting it into float without an explicit cast. Either we should type cast it or should directly call this method in println function otherwise we will get an error.
Next TopicJava Float
|