Pages

Friday 19 October 2012

Addition & Subtraction



Chapter 2: Arithmetic for Computers
Addition:
Binary Addition
·         The four basic rules for binary addition are:
1.      0 + 0 = 0           Sum of 0 with carry of 0
2.      0 + 1 = 1           Sum of 1 with carry of 0
3.      1 + 0 = 1           Sum of 1 with carry of 0
4.      1 + 1 = 10         Sum of 0 with carry of 1

Example:10+10=100 
  carry 1      1     0
+            1     0
        1    0     0
  • ·         10 + 10 = 100, because  in the basic rule 0+0=0 and 1+1=10. Since 1 is largest digit in the binary system , any sum is greater that  1 requires a digit to be carried over. 


    Addition Of Hexadecimal Operations
    ·        The hexadecimal system(base 16) with its 16 digits (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F).
    {A=10, B=11,C=12, D=13, E=14, F=15}
    ·        If any additions of hexadecimal operations have digits more that F like G,H,I,J,K, the addition does not have answer because the digits more that F is undefined.
    ·        Example:  123EFG + 456ABC this type of questions is undefined questions .
    ·         Example of additions of hexadecimal operations:
    1.      6616+3716
    2.      CD16+AB16

     Solution:

    1.                          6           616
                  +          3           7 16  

                                  9           1316 

      9           1316   =    9D16


    2.                1      1C            D16              (C=1210 , D=1310)
                +            A            B16                 (A=1010, B=1110)
                                    1         7            816
                          D + B= 1310 + 1110 = 2410
                                                             = 2410 - 1610 = 816 with a 1 carry
                         C+A+ carry from D+B that is 110 = 1210 + 1010 + 110 = 2310
                                                              2310 - 1610 = 716 with a 1 carry

    Subtraction:
    Binary Subtraction
    ·        The four basis rules for binary subtraction are:
    1.     0 - 0 = 0
    2.     1 - 1 = 0
    3.     1 -0  = 1
    4.     10 - 1 = 1            0-1 with a borrow of 1   
    ·         A borrow is required in binary subtraction only when we need to subtract a 1 from a 0 .

    Example: a.)11-10
                     b.)100-011
                    Solution:  a.)             
       1          1
                              -      1         0
                                                         0          1

     

    b.)                      1 0      0 2 1    20
                        -     0         1          1
                               0      0          1

    • ·         Left column: When a 1 is borrowed, a 0 is left , so 0 – 0 = 0.
    • ·         Middle column: Borrow 1 from  left  column , making 2 which mean 10 in     binary,when 2 borrowed it become 1,then 1 – 1 =0 .
    • ·         Right column: Borrow 1 from middle column , making 10 then 10-1=1.
     


     Subtraction Of Hexadecimal Operations
    ·        The hexadecimal system(base 16) with its 16 digits (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F).
    {A=10, B=11,C=12, D=13, E=14, F=15}

    ·        If any subtraction of hexadecimal operations have digits more that F like G,H,I,J,K, the addition does not have answer because the digits more that F is undefined.
    ·        Example:  123EFG  -  456ABC this type of questions is undefined questions .
    ·        Example of subtraction of hexadecimal operations:
                    1. 7516 - 2116
                       2. 5516 - 3B16
     
  • Solutions:
    1.                     7          516
                -           2          116
                             5         416




    2.                     5  4    16+516
                -           3          B16
                            1          A16       

    ·         Left  column   : When 5 is borrowed, a 4 is left, so 4 – 1 = 1 .
    ·         Right column :  Borrow 1 from left column , making 516+1616=2116  
                                ,so 2116 – B16 = A16  



    CHOO YIE YUNG(B031210026)
     





     

2 comments: