Java.lang.Float.floatToIntBits() 方法

描述

java.lang.Float.floatToIntBits() 方法根据 IEEE 754 浮点"单一格式"位布局返回指定浮点值的表示形式。它包括以下要点 −

  • 如果参数为正无穷大,则结果为 0x7f800000。
  • 如果参数为负无穷大,则结果为 0xff800000。
  • 如果参数为 NaN,则结果为 0x7fc00000。

声明

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

public static int floatToIntBits(float value)

参数

value − 这是一个浮点数。


返回值

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


异常

NA


示例

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

package com.tutorialspoint;

import java.lang.*;

public class FloatDemo {

   public static void main(String[] args) {

      Float f = new Float("10.07");
   
      // returns the bits that represent the floating-point number
      System.out.println("Value = " + f.floatToIntBits(5.5f));  
   }
}   

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

Value = 1085276160