[Math] Minimum number of bits to represent negative number

arithmeticbinarycomputational mathematicsfloating pointintegers

Minimum number of bits required to represent $(+32)_{base10}$ and $(-32)_{base10}$ in signed two's compliment form?

My attempt:

$32 = 0100000$ (1st bit $0$ – sign bit as positive)

So to represent $+32$ we need $7$ bits.

-32 = 1100000 (1st bit $1$ – sign bit as negative)

So to represent $-32$ we need $7$ bits.

But the answer is given as $6$ bits. His reason: one $1$ bit is enough to represent negative number. I am confused. Please clarify here.

Also I have following Questions:

Can we say number of bits required to represent a negative number is strictly less than (or less than equal to) the number of bits required to represent that corresponding positive number?

How can we generalize the minimum number of bits required to represent a given positive and negative number in signed magnitude representation, signed one's complement notation and signed two's compliment notation.

I know that the minimum number bits will be of order of $\log_2n$. But exactly how much, I am not able to think.

I know that the range of numbers in signed magnitude and signed one's complement is $-(2^{n-1} – 1)$ to $+(2^{n-1} – 1)$, while the range of numbers in signed two's complement representation is $-(2^{n-1})$ to $+(2^{n-1} – 1)$.

Best Answer

You wrote:


-32 = 1100000 (1st bit 1 - sign bit as negative)

So to represent -32 we need 7 bits


Let's consider a 6 bit, signed number given to us in a 2's complement representation: 100000

Signed bit is 1, so it's a negative number and we take 2's complement of the remaining bits, i.e. subtract 0 from 32, and we get:

-32.

One may also argue that it can correspond to negative 0. But in 2's complement, there is no negative 0 and that's why one can represent one extra number in 2's complement than in 1's complement with the same number of bits.

Hope it helps!