Java.lang.Float.floatToRawIntBits() 方法

描述

java.lang.Float.floatToRawIntBits() 方法根据 IEEE 754 浮点"单一格式"位布局返回指定浮点值的表示,保留 Not-a-Number ( NaN) 值。 它包括以下要点 −

  • 如果参数为正无穷大,则结果为 0x7f800000。
  • 如果参数为负无穷大,则结果为 0xff800000。
  • 如果参数是 NaN,则结果是表示实际 NaN 值的整数。 与 floatToIntBits 方法不同,floatToRawIntBits 不会将所有编码 NaN 的位模式折叠为单个"规范"NaN 值。

声明

以下是 java.lang.Float.floatToRawIntBits() 方法的声明。

public static int floatToRawIntBits(float value)

参数

value − This is a floating-point number.


返回值

此方法返回表示浮点数的位。


异常

NA


示例

下面的例子展示了 java.lang.Float.floatToRawIntBits() 方法的使用。

package com.tutorialspoint;

import java.lang.*;

public class FloatDemo {

   public static void main(String[] args) {

      Float f = new Float("20.12");

      //returns the bits that represent the floating-point number
      System.out.println("Value = " + f.floatToRawIntBits(9.0f));  
   }
}   

让我们编译并运行上面的程序,这将产生下面的结果 −

Value = 1091567616