java.lang.Float intBitsToFloat(int bits)
Description
The intBitsToFloat(int bits) method of Float class is use to get the float value corresponding to a given bit representation. The argument is considered to be a representation of a floating-point value according to the IEEE 754 floating-point “single format” bit layout.
Method Syntax
public static float intBitsToFloat(int bits)
Method Argument
Data Type | Parameter | Description |
---|---|---|
int | bits | an integer. |
Method Returns
The intBitsToFloat(int bits) method of Float class returns the float floating-point value with the same bit pattern.
Compatibility
Java 1.0
Discussion
There are some rules governing the intBitsToFloat() method and here as follows:
- If the argument is 0xff800000, the result is negative infinity.
- If the argument is 0xff800000, the result is negative infinity.
- this method may not be able to return a float NaN with exactly same bit pattern as the int argument.
Java Float intBitsToFloat(int bits) Example
Below is a simple java example on the usage of floatToIntBits(float value) method of Float class.
package com.javatutorialhq.java.examples; import java.util.Scanner; import static java.lang.System.*; /* * This example source code demonstrates the use of * intBitsToFloat(int bits) method of Float class. */ public class IntBitsToFloatExample { public static void main(String[] args) { // Ask user input for a number System.out.print("Enter a Number:"); // declare the scanner object Scanner scan = new Scanner(System.in); // use scanner to get value from user console int value = scan.nextInt(); // close the scanner object scan.close(); /* * code block to print the result of * intBitsToFloat(int bits) method */ out.println("Float value is "+Float.intBitsToFloat(value)); } }
Basically on the above example, we just ask for user input on the console and then we use the scanner object to get the input as primitive int. We then get the float equivalent of the integer using the method intBitsToFloat(int bits) of java Float.