-1
$\begingroup$

When using 2's complement with 4 bits, the largest positive int I can represent is 0111. The smallest negative one is 1000.

The smallest int should intuitively be the negative of 0111 - 1 = 0110 since we can represent one more positive than negative int.

If we invert the bits of 0110 and then add 1, however, we get 1010, which differs from 1000. What am I doing wrong?

$\endgroup$
2
$\begingroup$

The smallest int should intuitively be the negative of 0111 - 1 = 0110 since we can represent one more positive than negative int.

This is incorrect. If you'd, for example, read the Wikipedia article, you'd have seen that $n$-bit two's complement can store integers between $+2^{n-1}-1$ and $-2^{n-1}$. If two's complement worked the way you proposed, you'd only be able to represent $2^n-2$ different values in an $n$-bit field, which "wastes" two possible values: this would be worse than ones' complement, which "wastes" one value by being able to represent $-0$.

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.