“Java中的浮点型”的版本间的差异
跳到导航
跳到搜索
Jihongchang(讨论 | 贡献) (建立内容为“=== 怎样查看浮点型的二进制形式 === <syntaxhighlight lang="java"> public class Test2 { public static void main(String[] args) { int intB…”的新页面) |
Jihongchang(讨论 | 贡献) |
||
第12行: | 第12行: | ||
} | } | ||
− | </syntaxhighlight> | + | </syntaxhighlight><syntaxhighlight lang="console"> |
+ | 1178657918 | ||
+ | 1000110010000001110010001111110 | ||
+ | </syntaxhighlight>Float.floatToIntBits(float value) 方法返回的 int 型数据,就是 float 输入参数的二进制形式转换成对应的十进制值。 |
2022年11月12日 (六) 07:02的版本
怎样查看浮点型的二进制形式
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 输入参数的二进制形式转换成对应的十进制值。