整数的最大值

在C中,整数(对于32位机器)是32位,其范围从-32,768到+32,767。在Java中,整数也是32位,但范围从-2,147,483,648到+2,147,483,647。


我不明白Java中的范围是如何不同的,即使位数是相同的。有人可以解释一下吗?


慕尼黑8549860
浏览 751回答 3
3回答

慕勒3428872

在C语言中,语言本身并不确定某些数据类型的表示形式。它可以因机器而异,在嵌入式系统上int可以是16位宽,但通常是32位。唯一的要求是short int<= int<= long int按大小。此外,还有一个建议int应该代表处理器的本机容量。所有类型都签名。该unsigned修改器允许您使用最高位的值(否则它被保留为符号位)的一部分。以下是可能的数据类型的可能值的简短表:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minimum&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;maximumsigned&nbsp; &nbsp; 8 bit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -128&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +127signed&nbsp; &nbsp;16 bit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-32 768&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+32 767signed&nbsp; &nbsp;32 bit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -2 147 483 648&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +2 147 483 647signed&nbsp; &nbsp;64 bit&nbsp; -9 223 372 036 854 775 808&nbsp; &nbsp; &nbsp; +9 223 372 036 854 775 807unsigned&nbsp; 8 bit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +255unsigned 16 bit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+65 535unsigned 32 bit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +4 294 967 295unsigned 64 bit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0&nbsp; &nbsp; &nbsp;+18 446 744 073 709 551 615在爪哇,在Java语言规范确定的数据类型的表示。顺序是:byte8位,short16位,int32位,long64位。所有这些类型都是签名的,没有未签名的版本。但是,位操作会将数字视为无符号(即正确处理所有位)。字符数据类型char是16位宽,无符号,并使用UTF-16编码保存字符(但是,可以分配一个char表示无效字符代码点的任意无符号16位整数)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; width&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;minimum&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;maximumSIGNEDbyte:&nbsp; &nbsp; &nbsp;8 bit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -128&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +127short:&nbsp; &nbsp;16 bit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-32 768&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+32 767int:&nbsp; &nbsp; &nbsp;32 bit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -2 147 483 648&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; +2 147 483 647long:&nbsp; &nbsp; 64 bit&nbsp; -9 223 372 036 854 775 808&nbsp; &nbsp; &nbsp; +9 223 372 036 854 775 807UNSIGNEDchar&nbsp; &nbsp; &nbsp;16 bit&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;+65 535

米琪卡哇伊

在C中,整数(对于32位机器)是32位,其范围从-32768到+32767。错误。以2的补码表示的32位有符号整数的范围为-2 31到2 31 -1,等于-2,147,483,648到2,147,483,647。
打开App,查看更多内容
随时随地看视频慕课网APP