How does a two's complement number overflow?

1.6k Views Asked by At

The problem is to convert $32$ to $6$-bit two's complement or note that the range would overflow.

For $32$, I have: $100000$.

How does this overflow? Is it because the 1 means negative, so it would be $0100000$ but the space cannot accommodate this? But the notes say the max positive number is $2^5 - 1 = 31$.

1

There are 1 best solutions below

0
On BEST ANSWER

As you say, in twos complement the first bit represents the sign and the rest of the bits represent the number. Writing $32_{10}=100\ 000_2$ is not legal in twos complement as the leading bit being $1$ represents a negative number and $32_{10}$ is not negative. In $6$ bit twos complement the largest positive number you can represent is $31_{10}=011\ 111$. As you count down you get to $)_{10}=000\ 000$, then roll over to $-1_{10}=111\ 111$. As you keep counting down you finally get to $-32_{10}=100\ 000$, which is the most negative number you can represent. Your proposed representation of $32_{10}=100\ 000$ would be read as $-32_{10}$