Wei Ma
Wei Ma

Reputation: 3165

What is the value of binary 100...(31 zeros) for 32-bit integer?

It's just a random thought. The two's complement of 100...(31 zeros) is also 100... So, the value must be 0. But we know that the binary representation of 0 is 000...

I know it can't be a -0 and a +0 because every binary representation should map to a unique value.

Upvotes: 1

Views: 273

Answers (2)

R. Martinho Fernandes
R. Martinho Fernandes

Reputation: 234524

It's the smallest possible value: −231. It's not zero, because 100... is not zero. It's 231.

Upvotes: 2

Joey
Joey

Reputation: 354644

It's −231. Two's complement has only a single zero and the negative range extends one number further than the positive. And yes, that means that there is a single negative number that has no positive equivalent – this is sometimes called the »weird number« since it is an exception of how two's complement numbers are built.

Upvotes: 8

Related Questions