0

why the min int for 32bit is -2^31 not -2^31+1 ?

I can understand the max int is 2^31-1, so why the min int is not just the reversed of the max int -2^31+1?

Derek
  • 1
  • 2
  • This is not a universal truth, but a quirk of [2's complement](https://en.wikipedia.org/wiki/Two%27s_complement) representation that you should read about. – Eugene Sh. Apr 20 '23 at 14:34
  • Other than the reason, that 2's complement is kind of "industry standard" because it is convenient for computations, think that if it was just the "reverse" (as it does in sign-and-magnitude representation), then you will have one less number that can be represented in 32 bits, because you would then have two different representations of zero. It is an unnecessary waste. – Eugene Sh. Apr 20 '23 at 14:42
  • On a binary machine, powers of 2, there are always an even number of possible encodings to represent numbers. One is needed to represent 0, that leaves an odd number of encodings to represent non-zero positive and negative numbers. Necessarily they can't have the same range. Because of the sign bit in two's complement, there is one more for negative numbers. – Hans Passant Apr 20 '23 at 20:28
  • Hi Hans, "Because of the sign bit in two's complement, there is one more for negative numbers". can you help explain this? why sign bit increases one more for negative but not for positive? – Derek Apr 21 '23 at 13:38

0 Answers0