浮动类intBitsToFloat()方法 (Float class intBitsToFloat() method)
intBitsToFloat() method is available in java.lang package.
intBitsToFloat()方法在java.lang包中可用。
intBitsToFloat() method follows IEEE 754 floating-point standards and according to standards, it returns the float value corresponding to a given argument that denotes integer bits representation.
intBitsToFloat()方法遵循IEEE 754浮点标准,并且根据标准,它返回与表示整数位表示形式的给定参数相对应的浮点值。
intBitsToFloat() method is a static method, it is accessible with the class name too and if we try to access the method with the class object then also we will not get an error.
intBitsToFloat()方法是一个静态方法,也可以使用类名进行访问,如果尝试使用类对象访问该方法,那么也不会出错。
intBitsToFloat() method does not throw an exception at the time of converting bits representations to float value.
在将位表示形式转换为浮点值时, intBitsToFloat()方法不会引发异常。
Syntax:
句法:
public static float intBitsToFloat(int bits_rep);
Parameter(s):
参数:
int bits_rep – represents the integer value in bits.
int bits_rep –表示以位为单位的整数值。
Return value:
返回值:
The return type of this method is float, it returns the float value that represent the given argument in integer bits.
此方法的返回类型为float ,它返回以整数位表示给定参数的float值。
If we pass "0x7f800000", it returns the value "positive infinity".
如果我们传递“ 0x7f800000” ,它将返回值“ positive infinity” 。
If we pass "0xff800000", it returns the value "negative infinity".
如果我们传递“ 0xff800000” ,它将返回值“ negative infinity” 。
If value lies in between "0x7f800001" and "0x7fffffff" or the value lies in between "0xff800001" and "0xffffffff".
如果值在“ 0x7f800001”和“ 0x7fffffff”之间,或者值在“ 0xff800001”和“ 0xffffffff”之间 。
Example:
例:
// Java program to demonstrate the example
// of intBitsToFloat (int bits_rep)
// method of Float class
public class IntBitsToFloatOfFloatClass {
public static void main(String[] args) {
// Variables initialization
int value1 = 20;
int value2 = 0x7f800000;
int value3 = 0xff800000;
// Display value1,value2,value3 values
System.out.println("value1: " + value1);
System.out.println("value2: " + value2);
System.out.println("value3: " + value3);
// It returns the float value denoted by the given
// bit representation by calling Float.intBitsToFloat(value1)
float result1 = Float.intBitsToFloat(value1);
// It returns the float value denoted by the given
// bit representation by calling Float.intBitsToFloat(value2)
float result2 = Float.intBitsToFloat(value2);
// It returns the float value denoted by the given
// bit representation by calling Float.intBitsToFloat(value3)
float result3 = Float.intBitsToFloat(value3);
// Display result1,result2, result3 values
System.out.println("Float.intBitsToFloat(value1): " + result1);
System.out.println("Float.intBitsToFloat(value2): " + result2);
System.out.println("Float.intBitsToFloat(value3): " + result3);
}
}
Output
输出量
value1: 20
value2: 2139095040
value3: -8388608
Float.intBitsToFloat(value1): 2.8E-44
Float.intBitsToFloat(value2): Infinity
Float.intBitsToFloat(value3): -Infinity
翻译自: https://www.includehelp.com/java/float-class-intbitstofloat-method-with-example.aspx