How is the max number for a $32$-bit integer calculated?

$\begingroup$

I don't understand why $2, 147, 483, 647$ is the max number for a $32$-bit integer.

$8$ bits $= 1$ byte$32$ bits $= 4$ bytes

How is this calculated? $8^{32}$ is way over $2$ billion.

$\endgroup$ 1

2 Answers

$\begingroup$

Bits are the smallest unit of binary number system (like ones in decimal system). So if we have a 32-bit binary number, the largest possible binary number that can be written is $$(11111111111111111111111111111111)_2$$ which can be converted to decimal by the sum $$\sum_{i = 0}^{31}2^i = 2^{32}-1 = 4294967295$$

However, $2147483647$ is the largest integer in Two's Complement (signed in other words), which is represented by $$(01111111111111111111111111111111)_2$$ since first bit is called the sign bit.

$\endgroup$ $\begingroup$

A $32$ bit integer can be represented as $b_1b_2b_3\cdots b_{32}$, where all of these are bits (so they are either $0$ or $1$). There are $2^{32}$ possibilities for such integers.

If they are unsigned (i.e. always nonnegative), one can represent the integers $$0,1,\cdots,2^{32}-1.$$ If they are signed, one represents $$-2^{31},-\left(2^{31}-1\right),\cdots,-1,0,1,\cdots,2^{31}-2,2^{31}-1.$$

$\endgroup$ 3

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like