猿问
下载APP

整数的最大值

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


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


慕尼黑8549860
浏览 106回答 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。

阿波罗的战车

C语言定义指定各种数据类型的最小范围。因为int,该最小范围是-32767到32767,这意味着int必须至少为 16位宽。实现可以自由地提供int具有相应更宽范围的更宽类型。例如,在我使用的SLES 10开发服务器上,范围是-2147483647到2137483647。还有一些系统,在那里,使用16位int类型(所有的世界是不是一个VAX 86),但也有使用32位充足的int类型,也许使用64位等等。C语言旨在运行在不同的体系结构上。Java被设计为在隐藏这些架构差异的虚拟机中运行。
打开App,查看更多内容
随时随地看视频慕课网APP
我要回答