In C , the language itself does not determine the representation of certain datatypes.
(在C语言中,语言本身无法确定某些数据类型的表示形式。)
It can vary from machine to machine, on embedded systems the int
can be 16 bit wide, though usually it is 32 bit. (它因机器而异,在嵌入式系统上, int
可以为16位宽,尽管通常为32位。)
The only requirement is that short int
<= int
<= long int
by size.
(唯一的要求是short int
<= int
<= long int
的大小。)
Also, there is a recommendation that int
should represent the native capacity of the processor . (另外,建议int
应该代表处理器的本机容量 。)
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). (unsigned
修饰符允许您将最高位用作值的一部分(否则保留用于符号位)。)
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
In Java , the Java Language Specification determines the representation of the data types.
(在Java中 , Java语言规范确定数据类型的表示形式。)
The order is: byte
8 bits, short
16 bits, int
32 bits, long
64 bits.
(顺序为: byte
8位, short
16位, int
32位, long
64位。)
All of these types are signed , there are no unsigned versions. (所有这些类型都是带符号的 ,没有未签名的版本。)
However, bit manipulations treat the numbers as they were unsigned (that is, handling all bits correctly). (但是,位操作将数字视为无符号的(即,正确处理所有位)。)
The character data type char
is 16 bits wide, unsigned , and holds characters using UTF-16 encoding (however, it is possible to assign a char
an arbitrary unsigned 16 bit integer that represents an invalid character codepoint)
(字符数据类型char
为16位宽, 无符号 ,并使用UTF-16编码保存字符(但是,可以给char
分配一个代表无效字符代码点的任意无符号16位整数))
width minimum maximum
SIGNED
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
UNSIGNED
char 16 bit 0 +65 535
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…