Download as pdf or txt
Download as pdf or txt
You are on page 1of 18

WESTERN UNIVERSITY

Dept. of Electrical & Computer Engineering

DIGITAL LOGIC SYSTEMS


ECE 2277a: Digital Number Systems (Unit 1)
Lesson 4: Complements of Numbers
Part III: Subtraction Using Complements
Arash Reyhani (Section 1)
John McLeod (Section 2)
Subtraction of Unsigned Numbers
Using Complements

ECE 2277a: Unit 1-4 (III) Arash Reyhani 12


Subtraction of Unsigned Numbers
Using Complements
• The subtraction taught in elementary schools uses the borrow
concept

ECE 2277a: Unit 1-4 (III) Arash Reyhani 12


Subtraction of Unsigned Numbers
Using Complements
• The subtraction taught in elementary schools uses the borrow
concept
• This method is less efficient than the method using complements
when subtraction is performed with addition

ECE 2277a: Unit 1-4 (III) Arash Reyhani 12


Subtraction of Unsigned Numbers
Using Complements
• The subtraction taught in elementary schools uses the borrow
concept
• This method is less efficient than the method using complements
when subtraction is performed with addition
• It can be done using both the r’s and (r-1)’s complements.

ECE 2277a: Unit 1-4 (III) Arash Reyhani 12


Subtraction Using r’s Complement
The subtraction of two n-digit unsigned numbers M-N in base r
can be done as follows:

ECE 2277a: Unit 1-4 (III) Arash Reyhani 13


Subtraction Using r’s Complement
The subtraction of two n-digit unsigned numbers M-N in base r
can be done as follows:
1. Add M to the r's complement of N to obtain sum (S):
S=M+(rn- N) = M - N + rn

ECE 2277a: Unit 1-4 (III) Arash Reyhani 13


Subtraction Using r’s Complement
The subtraction of two n-digit unsigned numbers M-N in base r
can be done as follows:
1. Add M to the r's complement of N to obtain sum (S):
S=M+(rn- N) = M - N + rn
2. If M≥N → S=M-N+rn≥rn → S produces an end carry (rn).

ECE 2277a: Unit 1-4 (III) Arash Reyhani 13


Subtraction Using r’s Complement
The subtraction of two n-digit unsigned numbers M-N in base r
can be done as follows:
1. Add M to the r's complement of N to obtain sum (S):
S=M+(rn- N) = M - N + rn
2. If M≥N → S=M-N+rn≥rn → S produces an end carry (rn).
– The end carry should be discarded to obtain the result:
M-N=S-rn ≥ 0.

ECE 2277a: Unit 1-4 (III) Arash Reyhani 13


Subtraction Using r’s Complement
The subtraction of two n-digit unsigned numbers M-N in base r
can be done as follows:
1. Add M to the r's complement of N to obtain sum (S):
S=M+(rn- N) = M - N + rn
2. If M≥N → S=M-N+rn≥rn → S produces an end carry (rn).
– The end carry should be discarded to obtain the result:
M-N=S-rn ≥ 0.
3. If M<N → S=M-N+rn=r n-(N-M) < rn → S does not produce an
end carry (rn).

ECE 2277a: Unit 1-4 (III) Arash Reyhani 13


Subtraction Using r’s Complement
The subtraction of two n-digit unsigned numbers M-N in base r
can be done as follows:
1. Add M to the r's complement of N to obtain sum (S):
S=M+(rn- N) = M - N + rn
2. If M≥N → S=M-N+rn≥rn → S produces an end carry (rn).
– The end carry should be discarded to obtain the result:
M-N=S-rn ≥ 0.
3. If M<N → S=M-N+rn=r n-(N-M) < rn → S does not produce an
end carry (rn).
– The result will be M-N=- r's complement(S) < 0.

ECE 2277a: Unit 1-4 (III) Arash Reyhani 13


Subtraction Using r’s Complement
The subtraction of two n-digit unsigned numbers M-N in base r
can be done as follows:
1. Add M to the r's complement of N to obtain sum (S):
S=M+(rn- N) = M - N + rn
2. If M≥N → S=M-N+rn≥rn → S produces an end carry (rn).
– The end carry should be discarded to obtain the result:
M-N=S-rn ≥ 0.
3. If M<N → S=M-N+rn=r n-(N-M) < rn → S does not produce an
end carry (rn).
– The result will be M-N=- r's complement(S) < 0.

ECE 2277a: Unit 1-4 (III) Arash Reyhani 13


Subtraction Using (r-1)’s Complement

ECE 2277a: Unit 1-4 (III) Arash Reyhani 14


Subtraction Using (r-1)’s Complement
• It is similar to the r’s complement except
– r’s complement → (r-1)’s complement
– End cary → end-around carry

ECE 2277a: Unit 1-4 (III) Arash Reyhani 14


Subtraction Using (r-1)’s Complement
• It is similar to the r’s complement except
– r’s complement → (r-1)’s complement
– End cary → end-around carry
• Removing the end carry and adding 1 to the sum is referred to as
an end-around carry.

ECE 2277a: Unit 1-4 (III) Arash Reyhani 14


Subtraction Using (r-1)’s Complement
• It is similar to the r’s complement except
– r’s complement → (r-1)’s complement
– End cary → end-around carry
• Removing the end carry and adding 1 to the sum is referred to as
an end-around carry.
1. Obtain: S=M+(r-1)'s comp.(N) =M+(rn-1- N) = M - N + rn -1

ECE 2277a: Unit 1-4 (III) Arash Reyhani 14


Subtraction Using (r-1)’s Complement
• It is similar to the r’s complement except
– r’s complement → (r-1)’s complement
– End cary → end-around carry
• Removing the end carry and adding 1 to the sum is referred to as
an end-around carry.
1. Obtain: S=M+(r-1)'s comp.(N) =M+(rn-1- N) = M - N + rn -1
2. If M ≥ N →S will produce an end carry
• Discard it and add with 1 (end-around carry) to obtain the result:
M – N=S -rn +1

ECE 2277a: Unit 1-4 (III) Arash Reyhani 14


Subtraction Using (r-1)’s Complement
• It is similar to the r’s complement except
– r’s complement → (r-1)’s complement
– End cary → end-around carry
• Removing the end carry and adding 1 to the sum is referred to as
an end-around carry.
1. Obtain: S=M+(r-1)'s comp.(N) =M+(rn-1- N) = M - N + rn -1
2. If M ≥ N →S will produce an end carry
• Discard it and add with 1 (end-around carry) to obtain the result:
M – N=S -rn +1
3. If M < N →S does not produce an end carry
• The result is negative → M-N=-(r-1)'s comp. (S).

ECE 2277a: Unit 1-4 (III) Arash Reyhani 14

You might also like