我不明白 int 63823 为何比 double 1.0 占用更少的空间。在这个特定实例中,int 中是否没有存储更多信息?
最佳答案
I don't understand how an int 63823, takes up less space than a double 1.0. Is there not more information stored in the int, in this particular instance?
好问题。当您看到 63823
和 1.0
时,您所看到的是基础数据的表示,而您不是查看基础数据。它经过特殊格式化,以便您可以读取它,但不是机器如何看待它。
Java 使用非常特殊的格式来表示 int
和 double
。您需要查看those representations了解为什么 63823
在表示为 Java int
时需要 32 位,而 1.0
在表示为 Java 时需要 64 位>双
。
特别是,63823 在 Java 中作为 int
是 represented 如:
00000000000000001111100101001111
和 1.0 作为 double
是 represented在 Java 中为:
0011111111110000000000000000000000000000000000000000000000000000
如果你想探索更多,我推荐Two's Complement和 What Every Computer Scientist Should Know About Floating-Point Arithmetic .
关于java - 为什么 double 总是 8 个字节,而 int 总是 4 个字节,即使 int 有更多位数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17383158/