The maximum value of an n
-bit integer is 2n-1. Why do we have the \"minus 1\"? Why isn\'t the maximum just 2n?
If I ask you what is the biggest value you can fit into a 2-digit number, would you say it's 102 (100) or 102-1 (99)? Obviously the latter. It follows that if I ask you what the biggest n
-digit number is, it would be 10n-1. But why is there the "-1"? Quite simply, because we can represent 0 in a 2-digit number also as 00 (but everyone just writes 0).
Let's replace 10
with an arbitrary base, b
. It follows that for a given base, b
, the biggest n
-digit number you can represent is bn-1. Using a 32-bit (n = 32
) base-2 (b = 2
) number, we see that the biggest value we can represent 232-1.
Another way of thinking about it is to use smaller numbers. Say we have a 1-bit number. Would you tell me the biggest value it can represent is 21 or 21-1?