Java中的浮点型

来自姬鸿昌的知识库
Jihongchang讨论 | 贡献2022年11月12日 (六) 07:03的版本
跳到导航 跳到搜索

怎样查看浮点型的二进制形式

public class Test2 {

    public static void main(String[] args) {

        int intBits = Float.floatToIntBits(12345.12346f); //Bit Representation of the Float
        System.out.println(intBits); //1178657918
        System.out.println(Integer.toBinaryString(intBits));

    }

}
1178657918
1000110010000001110010001111110

Float.floatToIntBits(float value) 方法返回的 int 型数据,就是 float 输入参数的二进制形式转换成对应的十进制值。

验证二进制字符串对应浮点数