整型
整型 | |
---|---|
术语名称 | 整型 |
英语名称 | integral data type |
整型(integral data type)指计算机中处理整数的数据类型。 有时也不区分“整型”和“整数”两个词,但是整型因为表达范围受限,与整数并不一致。
根据实际面向的表达范围,整型被分为无符号整型(无符号整数)和有符号整型(有符号整数)两类, 并按照某种规则将允许的状态映射到等量的整数上。 通常情况下,这种规则对无符号数是二进制到十进制的普通转换,对有符号数使用补码作为有符号数和二进制表示的映射。
数据类型
逻辑结构
整型数据是一个数,之间可以进行算术运算和关系运算,一般也默认可以转换为表示范围足够大的浮点数。在部分语言中,也默认可以当作二进制串进行位运算。在部分语言中,可以默认转换为字符串或二值变量。
范围
由于历史上有不同的字节长度和字长,这里按照常见称呼,即字节 BYTE
为 8 位、字 WORD
表示 16 位的方式使用类型名称。这里 WORD
是为了兼容性从 16 为系统的标准继承下来的,并不意味着实际的字长。在现代化语言中,一般将位数直接作为类型名的一部分避免这种歧义。
名称 | 二进制位数 | 范围 | |||
---|---|---|---|---|---|
无符号整型 | 有符号整型 | ||||
原码/反码 | 补码 | ||||
半字节 | 4 | [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ 15=2^4-1 }[/math] |
[math]\displaystyle{ -7=-(2^3-1) }[/math] [math]\displaystyle{ 7 = 2^3-1 }[/math] |
[math]\displaystyle{ -8=-2^3 }[/math] [math]\displaystyle{ 7 = 2^3-1 }[/math] | |
字节 / BYTE / (u)int8
|
8 | [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ 255=2^8-1 }[/math] |
[math]\displaystyle{ -127=-(2^7-1) }[/math] [math]\displaystyle{ 127 = 2^7-1 }[/math] |
[math]\displaystyle{ -128=-2^7 }[/math] [math]\displaystyle{ 127 = 2^7-1 }[/math] | |
字 / WORD / (u)int16
|
16 | [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ 65535=2^{16}-1 }[/math] |
[math]\displaystyle{ -32767=-(2^{15}-1) }[/math] [math]\displaystyle{ 32767 = 2^{15}-1 }[/math] |
[math]\displaystyle{ -32768=-2^{15} }[/math] [math]\displaystyle{ 32767 = 2^{15}-1 }[/math] | |
双字 / DWORD / (u)int32
|
32 | [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ 4294967296=2^{32}-1 }[/math] |
[math]\displaystyle{ -2147483647=-(2^{31}-1) }[/math] [math]\displaystyle{ 2147483647 = 2^{31}-1 }[/math] |
[math]\displaystyle{ -2147483648=-2^{31} }[/math] [math]\displaystyle{ 2147483647 = 2^{31}-1 }[/math] | |
四字 / QWORD / (u)int64
|
64 | [math]\displaystyle{ 0 }[/math] [math]\displaystyle{ 18446744073709551616=2^{64}-1 }[/math] |
[math]\displaystyle{ -9223372036854775807=-(2^{63}-1) }[/math] [math]\displaystyle{ 9223372036854775807 = 2^{63}-1 }[/math] |
[math]\displaystyle{ -9223372036854775808=-2^{63} }[/math] [math]\displaystyle{ 9223372036854775808 = 2^{63}-1 }[/math] | |
八字 / OWORD / (u)int128
|
128 | 0 340282366920938463463374607431768211456 |
-170141183460469231731687303715884105727 170141183460469231731687303715884105727 |
-170141183460469231731687303715884105728 170141183460469231731687303715884105727 |