Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the minimum value of a 32-bit signed integer?

What is the minimum value of a 32-bit signed integer, happens to be the security "challenge" question in order to make an account at [this website](edit: link is now malware) (don't judge I'm just curious and bored).

I assumed they were talking about a typical 32bit int which can store numbers as big as 2,147,483,647. But when I tried -2147483647 it said I got the question wrong. I tried several variations such as -2,147,483,647 but nothing works...

Am I misinterpreting the question or is there something wrong with the web site?

PS I also tried -2,147,483,648 as suggested

Here's a picture enter image description here

like image 943
java Avatar asked Sep 29 '13 22:09

java


2 Answers

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.

like image 61
Timofey Avatar answered Oct 16 '22 08:10

Timofey


Signed 32 bit integers can go down to -2,147,483,648

like image 44
Zack Newsham Avatar answered Oct 16 '22 06:10

Zack Newsham