# 2's complement substraction

I need to perform 2's complement operations on -50 - -48

From a mathematical point of view the following would be true.

-50 + 48 = -2

If I would follow the steps I would have:

I got to this result by getting the bite for 50 and 48 and then reversing

-50 = 11001101
-48 = 11001111


In 2's complement:

the bite result for 11001101 - 11001111 is - 00000010 which is 2
the decimal result for 11001101 - 11001111 is -2.


Is my logic correct? I think I am missing something.

In two's complement, we compute $$a-b$$ by adding $$a$$ and $$-b$$. To compute $$-b$$ in two's complement, we invert all bits in $$b$$, and increment the result by $$1$$.
Let's see how it works in your example. You haven't specified the bit length, but it appears to be $$8$$. We have $$50 = 00110010$$, and so $$-50 = 11001101+1 = 11001110$$. Similarly, $$48 = 00110000$$, and so $$-48 = 11001111+1 = 11010000$$. In order to subtract $$-48$$ from $$-50$$, we first negate $$-48$$: $$-(-48) = 00101111+1 = 00110000$$. Now we add $$-50$$ and $$-(-48)$$: $$11001110+00110000 = 11111110$$. Since the MSB is $$1$$, we know that this is a negative number. To find out negative what, we invert it: $$-(11111110) = 00000001+1=00000010$$, which is $$2$$. Therefore $$-50-(-48)=-2$$.