Subtraction

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Subtraction

Ashley
Hey,

I am doing the ALU part. Everything is fine but I don't understand only one single part:

Why X - Y equals ~(~X + Y)?

I understood that X - Y equals X + (-Y), where (-Y) is represented as two's compliment, which is toggle all the bits in Y and then plus 1.

But I can't see any equality in adding (-Y)'s two's compliment and ~(~X + Y).

Please give me some hint,
Thanks,
Ashley
Reply | Threaded
Open this post in threaded view
|

Re: Subtraction

Koen_Be3840
                                          ~y               ~x

When x = 3 -> 0011 ( 3) -> 0011 ( 3) -> 1100 (-4)
and    y = 1 -> 0001 ( 1) -> 1110 (-2) -> 0001 ( 1)
----------------------------------------------------------
                                        0001 ( 1) -> 1101 (-3) -> 0010 ( 2)

                                                                              ~(~x+y)

View also negation

Koen
Reply | Threaded
Open this post in threaded view
|

Re: Subtraction

cadet1620
Administrator
In reply to this post by Ashley
Ashley wrote
I understood that X - Y equals X + (-Y), where (-Y) is represented as two's compliment, which is toggle all the bits in Y and then plus 1.

But I can't see any equality in adding (-Y)'s two's compliment and ~(~X + Y).

Here's an algebraic proof.
-a=~a+1
-a-1=~a
x-y=~(~x+y)
=-(-x-1+y)-1
=x+1-y-1
x-y=x-y

--Mark