Why is the maximum value of an unsigned n-bit integer 2^n-1 and not 2^n?

后端 未结 12 1226
萌比男神i
萌比男神i 2020-11-28 06:01

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?

12条回答
  •  北荒
    北荒 (楼主)
    2020-11-28 06:41

    It's because in computing, numbers start at 0. So if you have, for example, 32 address lines (232 addressable bytes), they will be in the range [0, 2^32).

提交回复
热议问题