整的最大值 [英] max value of integer
问题描述
在C,整数(32位机)是32位的,它的取值范围为-32768至+32767。
在Java中,整数也是32位,但范围是从-2,147,483,648到2,147,483,647
In C, the integer(for 32 bit machine) is 32 bit and it ranges from -32768 to +32767. In Java, the integer is also 32 bits but range is from -2,147,483,648 to 2,147,483,647
我不理解的范围内是如何用Java不同,即使比特数是相同的。有人可以解释吗?
I do not understand how the range is different in Java,even though the number of bits is the same. Can someone explain me?
推荐答案
在 C 的语言本身并不确定某些数据类型的再presentation。它可以改变从机器到机器,在嵌入式系统的 INT
可以是16位宽,但通常是32位。
In C, the language itself does not determine the representation of certain datatypes. It can vary from machine to machine, on embedded systems the int
can be 16 bit wide, though usually it is 32 bit.
唯一的要求是,短整型
< = INT
< = 长INT
按大小。此外,还有就是建议 INT
应该重新present处理器的本机容量
The only requirement is that short int
<= int
<= long int
by size. Also, there is a recommendation that int
should represent the native capacity of the processor.
所有类型签名。在无符号
修改,您可以使用最高位的值(否则它被保留为符号位)的一部分。
All types are signed. The unsigned
modifier allows you to use the highest bit as part of the value (otherwise it is reserved for the sign bit).
下面是可能的值可能的数据类型的短表:
Here's a short table of the possible values for the possible data types:
width minimum maximum
signed 8 bit -128 +127
signed 16 bit -32 768 +32 767
signed 32 bit -2 147 483 648 +2 147 483 647
signed 64 bit -9 223 372 036 854 775 808 +9 223 372 036 854 775 807
unsigned 8 bit 0 +255
unsigned 16 bit 0 +65 535
unsigned 32 bit 0 +4 294 967 295
unsigned 64 bit 0 +18 446 744 073 709 551 615
在的Java 的的的 Java语言规范决定了某些数据类型的再presentation。
In Java, the Java Language Specification determines the representation of the certain data types.
的顺序是:字节
8位,短
16位, INT
32位,长
64位。
The order is: byte
8 bits, short
16 bits, int
32 bits, long
64 bits.
width minimum maximum
byte: 8 bit -128 +127
short: 16 bit -32 768 +32 767
int: 32 bit -2 147 483 648 +2 147 483 647
long: 64 bit -9 223 372 036 854 775 808 +9 223 372 036 854 775 807
在Java中,所有类型的签署的,没有签名的版本。然而,位操作处理的数字,因为他们无符号(即正确处理所有位)。
In Java, all types are signed, there are no unsigned versions. However, bit manipulations treat the numbers as they were unsigned (that is, handling all bits correctly).
这篇关于整的最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!