32位有符号整数的最小值是多少?

时间:2013-09-29 22:55:12

标签: int 32-bit signed minimum

32位有符号整数的最小值是什么,恰好是在[本网站]创建帐户的安全性“挑战”问题(编辑:链接现在是恶意软件)(不要判断我“只是好奇和无聊”。

我认为他们在谈论一个典型的32位int,它可以存储与2,147,483,647一样大的数字。但当我尝试-2147483647时,它说我的问题是错的。我尝试了几种变体,例如-2,147,483,647,但没有任何效果......

我是否误解了这个问题,或者网站有什么问题吗?

PS我也按照建议尝试了-2,147,483,648

这是一张照片 enter image description here

3 个答案:

答案 0 :(得分:27)

The most used size of an integer is 32 bits. The last bit is used to distinguish positive and negative numbers. If the last bit is NOT set, then the number is positive. Therefore, the maximal positive number is 0x7FFFFFFF = (1<<31)-1=2147483647 (the last bit is not set).

For the negative numbers, two's complement notation is widely used. You can identify the counterpart of the positive number by inverting its all bits and adding 1. Thus, the counterpart for the maximal integer is 0x80000001, however it is NOT the minimal number.

The minimal number in two's complement notation is 0x80000000 = -2147483648. The interesting fact about this number is that it is equal to its own complement, i.e. inverting all bits results in 0x7FFFFFFF and adding 1 yields 0x80000000, which is equal to the original number.

More about two's complement notation in wikipedia.

答案 1 :(得分:7)

有符号32位整数可以降为-2,147,483,648

答案 2 :(得分:0)

也许ITS要求二进制或十六进制表格中的数字?