COMPLEMENTS - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

COMPLEMENTS

Description:

... higher significant position when the minuend digit is smaller than the ... Add the minuend M to the (r-1)'s complement of the subtrahend N. ... – PowerPoint PPT presentation

Number of Views:187
Avg rating:3.0/5.0
Slides: 14
Provided by: gabr202
Category:

less

Transcript and Presenter's Notes

Title: COMPLEMENTS


1
COMPLEMENTS
  • Complements are used in digital computers for
    simplifying the subtraction operations and for
    logical manipulation. There are two types of
    complements for each base-r system.
  • (1) the rs complement and
  • (2) the (r-1)s complement.
  • When the value of the base is substituted, the
    two types receives the names 2s and 1s
    complement for binary numbers or 10s and 9s
    complement for decimal numbers.

2
The rs Complement
  • Given a positive number N in base r with an
    integer part of n digits, the rs complement of N
    is defined as rn-N for N ? 0 and 0 for N0. The
    following numerical example will help clarify the
    definition.
  • The 10s complement of (52520)10 is 105-52520
    47480
  • The number of digits in the number is n5
  • The 10s complement of (0.3267)10 is 1- 0.3267
    0.6733
  • No integer part so 10n1001
  • The 10s complement of (25.639)10 is
    102-25.63974.361
  • The 2s complement of (101100)2 is (26)10
    (101100)2(1000000 - 101100)010100
  • The 2s complement of (0.0110)2 is
    (1-0.0110)20.1010

3
The (r-1)s Complement
  • Given a positive number N in base r with an
    integer part of n digits, the (r-1)s complement
    of N is defined rn-r-m-N. Some numerical examples
    follow
  • The 9s complement of (52520)10 is
    (105-1-52520)99999-5252047479.
  • No fraction party, 10-m1001
  • The 9s complement of (0.3267)10 is
    (1-10-4-0.3267)0.9999-0.32670.6732
  • No integer part, so 10n1001.
  • The 9s complement of (25.639)10 is
    (102-10-3-25.639)99.999-25.63974.360
  • The 1s complement of (101100)2 is (26-1)
    (101100)(111111-101100)010011.
  • The 1s complement of (0.0110)2 is (1-2-4)10
    (0.0110) 2 (0.1111-0.0110)2 0.1001

4
  • From the examples, we see that the 9s complement
    of a decimal number is formed simply by
    subtracting every digit from 9. The 1s
    complement of a binary number is even simpler to
    form. The 1s are changed to 0s and the 0s to
    1s. Since the (r-1)s complement is very easily
    obtained.
  • It is sometimes convenient to use it when the rs
    complement is desired. From the definitions and a
    comparison of the results obtained in the
    examples, it follows that the rs complement can
    be obtained from the (r-1)s complement after the
    addition of r-m to the least significant digit.
    For example, the 2s complement of 10110100 is
    obtained from the 1s complement 01001011 by
    adding 1 to give 01001100.

5
Subtraction with rs complement
  • The direct method of subtraction taught in
    elementary schools uses the borrow concept. In
    this method, we borrow a 1 from a higher
    significant position when the minuend digit is
    smaller than the corresponding subtrahend digit.
  • This seems to be easiest when people perform
    subtraction with paper and pencil. When
    subtraction is implemented by means of digital
    components, this method is found to be less
    efficient than the method that uses complements
    and addition as stated below. The subtraction of
    two positive numbers (M-N), both of base r, may
    be done as follows

6
  • Add the minuend M to the rs complement of the
    subtrahend N.
  • inspect the result obtained in step 1 for an end
    carry
  • if an end carry discard it.
  • If an end carry does not occur take the rs
    complement of the number obtained in step 1 and
    place a negative sign in front.
  • The following examples illustrate the
    procedures using 10s complement.

7
  • Subtract 72532-3250
  • M72532
    72532
  • N03250
  • 10s complement of N
    96750
  • End carry 1 69282
  • Answer 69282
  • Subtract (3250-72533)10
  • M03250
  • N72532
  • 03250
  • 10s complement of N
    27468
  • No
    carry 30718
  • Answer -69282(10s complement of 30718)

8
Subtraction with (r-1)s complement
  • The procedure for subtraction with the (r-1)s
    complement is exactly the same as oe variation,
    called, end-around carry as shown below. The
    subtraction of M-N, both positive numbers in base
    r, may be calculated in the following manner.
  • Add the minuend M to the (r-1)s complement of
    the subtrahend N.
  • inspect the result obtained in step 1 for an end
    carry
  • if an end carry occurs, add 1 to the least
    significant digit (end-around carry)
  • if an end does not occur, take the (r-1)s
    complement of the number obtained in step 1 and
    place a negative sign infront.

9
  • Example
  • M 72532
  • N03250
  • 72532
  • 9s complement of N
    96749

  • 69281
  • End around carry
    1
  • 69282
  • Answer 69282
  • M 03250
  • N 72532
  • 03250
  • 9s complement of N 27467
  • No carry
    30717
  • Answer-69282 -(9s complement of 30717)

10
  • Using 1s complement
  • (a) M 1010100
  • N 1000100
  • 1s complement of N 0111011
  • 1010100
  • 0111011
  • End-around carry 1 0001111

  • 1

  • 0010000
  • Answer 10000
  • M1000100
  • N1010100
  • 1s complement of N 0101011
  • 1000100
  • 0101011
  • No carry 1101111
  • Answer -10000 -(1s complement of 1101111)

11
  • Use 2s complement to perform M-N with the given
    binary numbers.
  • M1010100
  • N1000100

  • 1010100
  • 2s complement of N
    0111100

  • End carry 1 0010000
  • M 1000100
  • N1010100

  • 1000100
  • 2s complement of N 0101100
  • No carry 0010000
  • Answer -10000 -(2s complement of 1110000)

12
Comparison between 1s and 2s Complements
  • A comparison between 1s and 2s complements
    reveals the advantages and disadvantages of each.
  • The 1s complement has the advantage of being
    easier to implement by digital components since
    the only thing that must be done is to change 0s
    to 1s and 1s to 0s.
  • the implementation of the 2s complement may be
    obtained in two ways (1) by adding 1 to the
    least significant digit of the 1s complement,
    and
  • (2) by leaving all leading 0s in the least
    significant positions and the first 1 unchanged,
    and only then changing all 1s into 0s and all
    0s into 1s.
  • During subtraction of two numbers by complement,
    the 2s complement is advantageous in that only
    arithmetic addition operation is required.
  • The 1s complement requires two arithmetic
    additions when an end-around carry occurs. The
    1s complement has the additional disadvantage of
    possessing two arithmetic zeros one with all
    0sand one with all 1s.

13
  • To illustrate this fact, consider the subtraction
    of the two equal binary numbers 1100- 11000
  • Using 1s complement
  • 1100
  • 0011
  • 1111
  • Complement again to obtain -0000.
  • Using 2s complement
  • 1100
  • 0100
  • 0000
  • while the 2s complement has only one arithmetic
    zero, the 1s complement zero can be positive or
    negative, which may complicate matters
Write a Comment
User Comments (0)
About PowerShow.com