Java.lang.Float.intBitsToFloat() 方法

描述

java.lang.Float.intBitsToFloat() 方法返回对应于给定位表示的浮点值。 根据 IEEE 754 浮点"单一格式"位布局,该参数被认为是浮点值的表示。它包括以下要点 −

  • 如果参数为 0x7f800000,则结果为正无穷大。
  • 如果参数为 0xff800000,则结果为负无穷。
  • 如果参数是 0x7f800001 到 0x7fffffff 范围内或 0xff800001 到 0xffffffff 范围内的任何值,则结果为 NaN。

声明

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

public static float intBitsToFloat(int bits)

参数

bits − 这是一个整数。


返回值

此方法返回具有相同位模式的浮点值。


异常

NA


示例

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

package com.tutorialspoint;

import java.lang.*;

public class FloatDemo {

   public static void main(String[] args) {

      Float f = new Float("2.50f");
   
      /* returns the floating-point value with the same bit pattern */
      System.out.println(f.intBitsToFloat(123));
      System.out.println(f.intBitsToFloat(0x7f800000));  
      System.out.println(f.intBitsToFloat(0xff800000));  
   }
}   

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

1.72E-43
Infinity
-Infinity