Page 75 - Programmable Logic Controllers, Fifth Edition
P. 75

into  higher-order  columns,  as  shown  in  the  following
               examples.                                               EXAMPLE 10-2
               Decimal        Equivalent binary                        Subtract 111 from 100.
                    5                    101                                                  111
                  +2                   +  10                                                −100
                    7                    111                                                −011
                                       carry                           Subtract 11011 from 10111.
                                        1                                                    11011
                   10                  10  10                                              −10111
                 + 3                 +    11                                               −00100
                   13                  11  01
                                 carry  carry
                                    1 1                                 There are other methods available for doing subtraction:
                   26                 1  1010                           1’s complement
                 +12              +     1100                            2’s complement
                   38               1  0  0110
                                                                        The procedure for subtracting numbers using the 1’s
                  In arithmetic functions, the initial numeric quantities   complement is as follows:
               that are to be combined by subtraction are the minuend
               and subtrahend. The result of the subtraction process is   Step 1  Change the subtrahend to 1’s complement.
               called the difference, represented as:                   Step 2  Add the two numbers.
                                   A (minuend)                          Step 3  Remove the last carry and add it to the number
                                 −B (subtrahend)                              (end-around carry).
                                   C (difference)                    Decimal      Binary
                                                                         10         1010               1010
                  To subtract from larger binary numbers, subtract col-                   1’s complement
               umn by column, borrowing from the adjacent column       − 6        −0110              +1001
               when necessary. Remember that when borrowing from          4          100              10011
               the adjacent column, there are now two digits, i.e., 0 bor-             End-around carry     +1
               row 1 gives 10.                                                                           100
                                                                        When there is a carry at the end of the result, the result
                 EXAMPLE 10-1                                        is positive. When there is no carry, then the result is nega-
                                                                     tive and a minus sign has to be placed in front of it.
                 Subtract 1001 from 1101.
                                       1101
                                      −1001                            EXAMPLE 10-3
                                       0100                            Subtract 11011 from 01101.

                 Subtract 0111 from 1011.                                          01101
                                       1011                                   + − 00100   The 1’s complement
                                      −0111                                        10001   There is no carry,
                                       0100                                               so we take the 1’s
                                                                                          complement and add
                                                                                          the minus sign:
                  Binary numbers can also be negative. The procedure                      −01110
               for this calculation is identical to that of decimal num-
               bers because the smaller value is subtracted from the
               larger value and a negative sign is placed in front of   For subtraction using the 2’s complement, the 2’s com-
               the result.                                           plement is added instead of subtracting the numbers.



               56         Chapter 3  Number Systems and Codes







          pet73842_ch03_046-060.indd   56                                                                               03/11/15   3:50 PM
   70   71   72   73   74   75   76   77   78   79   80