Two's complement and a number without a representation in a computer

41 Views Asked by At

For the sake of the example, suppose we are working in a $4$ bit numbers. Then, addition is done modulo $2^{n}.$ In a computer numbers from $0$ to $7$ will be our positives, and $8$ to $15$ the negatives. Hence, to find the additive inverse of a number $x$, we calculate $2^{n} - x$. Every positive number has an inverse in this system, but the number $-8,$ which is $8$ modulo $2^{4}$ has no additive inverse representation in this system, since $2^{4} - 8 = 8 \equiv -8.$

So, how would a program to compute $$-8 + x = 0$$ work on such a $4$ bit computer?

1

There are 1 best solutions below

0
On BEST ANSWER

The number representation you are describing is called 4-bit 2s complement. It can only represent the integers $-8, -7, \ldots 0, 1, \ldots 7$. So if you use this number representation, you cannot give the solution to $-8 + x = 0$ (namely $x = 8$). So a program that was restricted to 4-bit 2s complement numbers would have to use two 4-bit numbers to represent the solution to this problem. See https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic.