Binary Subtraction with negative result

5.5k Views Asked by At

I want to do this little subtraction (but with bits): $1372 - 9714$

The binary code I found for $1372$ is: $00010101011100$ The binary code I found for $9714$ is: $10010111110010$

Then I added a sign bit $(0)$ for $9714$ and I calculated the two's complement: $101101000001110$

Next, I added this code with the binary code for $1372$ (with an extra sign bit for $1372$) and this resulted in : $101111101101010$ with the first '$1$' as a negative sign bit, this is the binary equivalent of $- 8042$.

What did I do wrong? Do I need to the calculate the two's complement of the result because it is negative?

1

There are 1 best solutions below

0
On BEST ANSWER

Your conversion of the result from two's complement seems to be flawed: The binary representation of the result in $15$-bit two's complement is indeed $101111101101010$, which is negative since its most significant bit is $1$.

Now, let's negate this number by first flipping all bits, yielding $010000010010101$, and then incrementing the result to get $010000010010110$. Converting this to decimal, one obtains $8342$, which is exactly the negative of the expected result (remember, we negated the binary representation!).