4.3 Is two’s complement a good fit?

Can we use C2(x) as -(x)?

Let us try the rules of negation of two’s complement.

First of all, is it true that C2(C2(x)) = x?

C (C (x))  =  (2n - 1)- C (x)+ 1                                 (16)
  2 2           n       2n
           =  (2 - 1)- (2 - 1- x + 1)+ 1                         (17)
           =  x                                                  (18)

However, this alone isn’t enough. Let us see if x + C2(x) = 0:

x+ C2(x)  =  x + (2n - 1- x +1)                              (19)
          =  2n                                             (20)
          =  0                                              (21)

Why does 2n = 0? This is because we are using modulo-2n arithmetics. Recall that in modulo arithmetic, 2n (2n mod2n) 0.

Now, on to some real tests. How about y + C2(x) = y - x?

                  n
y+ C2(x)  =  y + (2  - 1- x+ 1)                              (22)
          =  y - x+ (2n)                                    (23)
          =  y - x                                          (24)