Java Float类floatToIntBits()方法与示例

Float类floatToIntBits()方法 (Float class floatToIntBits() method)

  • floatToIntBits() method is available in java.lang package.

    floatToIntBits()方法在java.lang包中可用。

  • floatToIntBits() method follows IEEE 754 floating-point standards and according to standards, it returns the bits representation that denotes floating-point value.

    floatToIntBits()方法遵循IEEE 754浮点标准,并且根据标准,它返回表示浮点值的位表示形式。

  • floatToIntBits() 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.

    floatToIntBits()方法是一个静态方法,也可以使用类名进行访问,如果尝试使用类对象访问该方法,那么也不会收到错误。

  • floatToIntBits() method does not throw an exception at the time of representing bits.

    floatToIntBits()方法在表示位时不会引发异常。

Syntax:

句法:

    public static int floatToIntBits(float f);

Parameter(s):

参数:

  • float f – represents the single precision floating point value.

    float f –表示单精度浮点值。

Return value:

返回值:

The return type of this method is float, it returns the bits that represent the single precision floating-point value.

此方法的返回类型为float ,它返回表示单个精度浮点值的位。

  • If we pass "positive infinity", it returns the value "0x7f800000".

    如果我们传递“ positive infinity” ,它将返回值“ 0x7f800000”

  • If we pass "negative infinity", it returns the value "0xff800000".

    如果我们传递“负无穷大” ,它将返回值“ 0xff800000”

  • If we pass "NaN", it returns the value "0x7fc00000".

    如果我们传递“ NaN” ,它将返回值“ 0x7fc00000”

Example:

例:

// Java program to demonstrate the example 
// of floatToIntBits (float value)
// method of Float class

public class FloatToIntBitsOfFloatClass {
    public static void main(String[] args) {
        // Variables initialization
        float value1 = 18.20f;
        float value2 = 19.20f;

        // Display value1,value2 values
        System.out.println("value1: " + value1);
        System.out.println("value2: " + value2);

        // It returns the bits denoted by the single 
        // precision floating-point argument by calling 
        // Float.floatToIntBits(value1)
        int result1 = Float.floatToIntBits(value1);

        // It returns the bits denoted by the single 
        // precision floating-point argument by calling 
        // Float.floatToIntBits(value2)
        int result2 = Float.floatToIntBits(value2);

        // Display result1,result2 values
        System.out.println("Float.floatToIntBits(value1): " + result1);
        System.out.println("Float.floatToIntBits(value2): " + result2);
    }
}

Output

输出量

value1: 18.2
value2: 19.2
Float.floatToIntBits(value1): 1100061082
Float.floatToIntBits(value2): 1100585370


翻译自: https://www.includehelp.com/java/float-class-floattointbits-method-with-example.aspx

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值