Question

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

My attempt:

32 = 0100000 ( 1st zero - 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 answer is given as 6 bits to store -32 and 7 bits to store +32(positve case i understood, negative in my opinion it should be 7 bits). His reason - one 1 bit 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) number of bits required to represent that corresponding positive number?

how can we generalise minimum number of bits required to represent a given positive and negative number say +N and -N in signed magnitude representation, signed 1's complement notation and signed two's compliment notation.

Was it helpful?

Solution

The representations of the numbers as 6-bit two's complement binaries are \begin{align} +32_{10} &= 10\,0000_2\\ -32_{10} &= \overline{10\,0000}_2 + 1_2\\ &= 01\,1111_2 + 1_2\\ &= 10\,0000_2 \end{align} which would give the same representation for both numbers. That means you cannot use 6-bits numbers to represent both values using two's complement.

For 7-bit binaries it works, however: \begin{align} +32_{10} &= 010\,0000_2\\ -32_{10} &= \overline{010\,0000}_2 + 1_2\\ &= 101\,1111_2 + 1_2\\ &= 110\,0000_2 \end{align} As you can see, the most significant bit represents the sign of the number.


Another perspective on your question: What is the biggest positive/smallest negative number you can store in an $n$-bit two's complement binary? Then the answer is $2^{(n-1)}-1$ for the biggest positive and $-2^{(n-1)}$ for the smallest negative number.

That means that a 6-bit binary can hold values $-32, \ldots, 31$ and a 7-bit binary values $-64, \ldots, 63$. The number $-32$ then fits into the range of 6-bit binaries, while $+32$ doesn't. You'd need one more bit for the latter.

OTHER TIPS

There are 65 values x with -32 <= x <= +32. You cannot represent 65 values in 6 bits. Either you misread the question, or the answer 6 is wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with cs.stackexchange
scroll top