Why does the range of int has a minus 1?

后端 未结 5 1722
夕颜
夕颜 2021-02-15 11:17

I read that the range of an int is dependent on a byte.

So taking int to be 4 bytes long, thats 4 * 8 bits = 32 bits.

So the range should be : 2 ^ (32-1) = 2 ^ (

5条回答
  •  太阳男子
    2021-02-15 11:34

    232-1 is not same as 232 - 1 (as 0 is included in the range, we subtract 1)

    For your understanding, let us replace by small number 4 instead of 32

    24-1 = 8 whereas 24-1 = 16-1 = 15.

    Hope this helps!

提交回复
热议问题