Thursday, August 12, 2010

Addition & Subtraction - Other Number System


Subtraction of Octal number, Hexadecimal and Decimal can be done using compliments too. Therefore, a few examples are given below for Octal - 7 and 8 compliment, Hexadecimal - 15 and 16 compliments and for Decimal - 9 and 10 compliments.


Octal Number

Example : Using 7 Compliments

(1546)8 - (467)8


Minuend : 1546 and Subtrahend : 467. Minuend contain 4 digits where Subtrahend having 3, so add a leading 0 to Subtrahend 0467. Now 7'th compliment mean subtract the Subtrahend from 7's.


  7 7 7 7
  0 4 6 7
-------------
  7 3 1 0
-------------

Now add the Subtrahend to the minuend

   1
   1 5 4 6
+ 7 3 1 0
-------------
1 1 0 5 6         (Discard the Carry [1])
-------------
    1 0 5 6
            1  ( Adding Carry digits [Refer to Binary subtraction])
-------------
    1 0 5 7

Result of : (1546)8 - (467)8 = (1057)8



Example : Using 8 Compliments

(1546)8 - (467)8


Minuend : 1546 and Subtrahend : 467. Minuend contain 4 digits where Subtrahend having 3, so add a leading 0 to Subtrahend 0467. Now 7'th compliment mean <> subtract the Subtrahend from 7's.

  7 7 7 7
  0 4 6 7
-------------
  7 3 1 0
+        1     (Add one to the 7 compliment)
-------------
  7 3 1 1    Now add the Subtrahend to the minuend
-------------  

           1
   1 5 4 6
+ 7 3 1 1
-------------
1  1 0 5 7  (discard the Carry digits)
-------------

Result of : (1546)8 - (467)8 = (1057)8



Hexadecimal Number

Subtraction of Hexadecimal number can be done with with 15 or 16 compliments
Example : Using 15 Compliments

(15CB)16 - (2BC)16 = 1 5 12 11 - 2 11 12

Minuend : 15CB and Subtrahend : 2BC Minuend contain 4 digits where Subtrahend having 3, so add a leading 0 to Subtrahend 0 2 11 12. Now 15'th compliment mean  subtract the Subtrahend from 15's.

15 15 15 15
  0   2 11 12
-------------
 15 13  4  3    Now add the Subtrahend to the minuend
-------------

1 1
   1  5 12  11
 15 13   4   3
---------------
1 1 3 0 14
              1 ( Remove the extra carry digits and add it to the remainder)
-------------
1 3 0 15 = 130F

Result of : (15CB)16 - (2BC)16 = (130F)16



Example : Using 16 Compliments

(15CB)16 - (2BC)16 = 1 5 12 11 - 2 11 12

Minuend : 15CB and Subtrahend : 2BC Minuend contain 4 digits where Subtrahend having 3, so add a leading 0 to Subtrahend 0 2 11 12. Now 15'th compliment mean subtract the Subtrahend from 15's.

15 15 15 15
  0   2 11  12
---------------
 15 13  4   3
+               1 (Add 1 [16 Compliment])
---------------
 15 13  4  4  Now add the Subtrahend to the minuend
---------------
  1   1
  1   5 12 11
15 13  4    4
--------------
1 1  3   0  15 ( Discard the Carry digit)
--------------
1 3 0 15 = 130F

Result of : (15CB)16 - (2BC)16 = (130F)16

Decimal Number

We can do it for our (yes our) Decimal number system too. Subtraction of decimal number can be done with with 9 or 10 compliments

Example : Using 9 Compliments

(1497)10 - (879)10

Minuend : 1497 and Subtrahend : 879 Minuend contain 4 digits where Subtrahend having 3, so add a leading 0 to Subtrahend 0879 . Now 9'th compliment mean subtract the Subtrahend from 9's.

 9 9 9 9
 0 8 7 9
----------
 9 1 2 0                 Now add the Subtrahend to the minuend
----------
     1
 1  4  9  7
 9  1  2  0
--------------
1 0 6 1 7
            1      ( Remove the extra carry digits and add it to the remainder) +1
---------------
6 1 8

Result of : (1497)10 - (879)10=(618)10


Example : Using 10 Compliments

(1497)10 - (879)10

Minuend : 1497 and Subtrahend : 879 Minuend contain 4 digits where Subtrahend having 3, so add a leading 0 to Subtrahend 0879 . Now 9'th compliment mean subtract the Subtrahend from 9's.

  9 9 9 9
  0 8 7 9
----------
  9 1 2 0       (add 1 to make it 10 compliment)
        + 1
----------
  9 1 2 1        Now add the Subtrahend to the minuend
----------

      1
   1 4 9 7
   9 1 2 1
--------------
1 0 6 1 8      (Discard the carry digits)
-------------
      6 1 8 
-------------

Result of : (1497)10 - (879)10= (618)10



We yet to finish with number system, but promise you, next one will be the last
in these series!.