Lecture3 Chapter1 - Unsigned Numbers, Subtraction of Unsigned Numbers Using Complements
Lecture3 Chapter1 - Unsigned Numbers, Subtraction of Unsigned Numbers Using Complements
Numbers
Lecture3- Study Complements, Perform Subtraction
using Complements
Engr. Arshad Nazir, Asst Prof
Dept of Electrical Engineering
Fall 2022 SEECS 1
Objectives
• Study Complements
• Perform Subtraction of Unsigned Numbers using
Complements
Fall 2022 2
Complements
• Complements are used in digital computers to simplify the subtraction
operation and for logical manipulation. We can perform subtraction by
adder circuits i.e
A – B = A+(-B)
• There are two types of complements for each base-r system:
The radix complement, called the r’s complement.
The diminished radix complement, called the (r-1)’s complement.
• When the value of the base r is substituted in the name, the two types
are referred as the 2’s complement and 1’s complement for binary
numbers and the 10’s complement and 9’s complement for decimal
numbers.
Fall 2022 3
Fall 2022 4
Fall 2022 5
Fall 2022 6
Fall 2022 7
Diminished Radix Complement (DRC)
• Given a number N in base r having n digits, the (r-1)’s complement of N
is defined as:
(rn – 1) – N; where
r: radix or base of the given number
n: number of digits of integer part
N: Given number
• Decimal numbers are in base-10.
(r-1) = (10-1) = 9.
• The 9’s complement would be defined as:
(10n – 1) – N
• So, to determine the 9’s complement of 52:
(102 – 1) – 52 = 47
• Another example is to determine the 9’s complement of 3124:
(104 – 1) – 3124 = 6875
Fall 2022 8
Finding Diminished Radix Complement
(DRC)
• The DRC or (r-1)’s complement of decimal number is obtained by
subtracting each digit from 9
• The (r-1)’s complement of octal or hexadecimal number is obtained
by subtracting each digit from 7 or F, respectively
• The DRC (1’s complement) of a binary number is obtained by
subtracting each digit from 1. It can also be formed by changing 1’s to
0’s and 0’s to 1’s
Fall 2022 9
Diminished Radix Complement for
Binary Numbers
• For binary numbers r = 2 and (r-1) = 1. So, the 1’s complement would be
defined as:
(2n – 1) – N
• To determine the 1’s complement of 1000101:
(27 – 1) – 1000101 = 0111010
• To determine the 1’s complement of 11110111101:
(211 – 1) - 11110111101 = 00001000010
Note: 1’s complement can be done by switching all 0’s to 1’s and 1’s to 0’s.
Fall 2022 10
Complements
Radix Complement (r’s Complement)
The r’s complement of an n-digit number N in base-r is defined as:
rn – N ; for N 0
0 ; for N = 0
• We may obtain r’s complement by adding 1 to (r-1)’s complement. Since rn – N = [(rn –
1) – N]+1
• 10’s complement of 3229 is:
104 – 3229 = 6771
• 2’s complement of 101101 is:
26 – 101101 = 010011
Note that to determine 2’s complement, leave the least significant 0’s and the first 1
unchanged and then switch the remaining 1’s to 0’ and 0’s to 1’s.
Fall 2022 11
2’s Complement
• Another method to find 2’s complement is
Complement (reverse) each bit
Add 1
• Example:
Fall 2022 12
Notes on Complements
• A couple of points on complements to keep in mind:
If you are trying to determine the complement of a value that
contains a radix point:
o Remove the radix point.
o Determine the complement.
o Replace the radix point in the same relative position.
The complement of a complement will restore the original number i.e
N= 2n – 1 – [ (2n – 1) – N] 1,s complement
N=rn – ( rn – N) 2,s complement
Fall 2022 13
Your Turn
• Find 9’s and 10’s complement of the following:
N=972.85
N=0.975
7256
• Find 1’s and 2’s complement of the following:
1011.101
0.10110
1101101
Fall 2022 14
Subtraction with Complements
• In digital computers the use of borrows to complete subtraction is inefficient.
Complements are used to overcome this inefficiency.
• The subtraction of two n-digit unsigned numbers M – N in base r can be done as
follows:
Add the minuend, M, to the r’s complement of the subtrahend, N:
o M-N= M + (rn – N) = M – N + rn
If M N, the sum will produce an end carry, rn, which can be discarded by -rn ;
what is left is the result of M – N. This gives us correct answer
o If M N, the sum does not produce an end carry and is equal to rn – (N – M),
which is the r’s complement of (N – M). This shows –ve answer expressed in r’s
complement form. To obtain the answer in a familiar form, take the r’s
complement of the sum and place a negative sign in front i.e –(N-M).
Fall 2022 15
10’s Complement Subtraction
• Using 10’s complement, subtract 62513 – 2140
• Note that the extra 9 in the 10’s complement of N is to fill the space
holder 0.
Fall 2022 16
10’ Complement Subtraction
• Using 10’s complement, subtract 2140 - 62513
Fall 2022 17
2’s Complement Subtraction
• Using 2’s complement, subtract 1001001 - 1000110
Fall 2022 18
2’s Complement Subtraction
• Using 2’s complement, subtract 1000110 - 1001001
Fall 2022 19
Subtraction with r-1’s Complement
• The subtraction of two n-digit unsigned numbers M – N in base r using r – 1’s
complement can be done as follows:
Add the minuend, M, to the r – 1’s complement of the subtrahend, N:
o M – N= M+(– N)= M + (r – 1’s complement of N)= M+[(rn –1) – N] =
M – N +(rn – 1)
If M > N, M – N , a +ve value after added to rn –1 will produce an end carry, rn
, which can be discarded by -rn and 1 added to the least significant digit (LSD)
of SUM i.e end around carry.; what is left is the result of M – N. This gives us
correct +ve answer. Examples are 72532 – 3250 and 1010100 – 1000011.
Mathematically,
o M – N= M – N +rn – 1 – rn+ 1
If M≤ N, M – N= (rn – 1) – (N – M). Here (N – M) is a +ve value and after
subtracted from rn – 1, doesn’t produce an end carry . The result (rn – 1) – (N –
M) shows r – 1’s complement of (N – M). This shows – ve answer. To obtain the
answer in a familiar form, take the r – 1’s complement of the SUM and place a
– ve sign in front i.e – (N – M). Examples are 3250 – 72532 and 1000011 –
1010100. Mathematically,
o M – N= (rn – 1) – (N – M)= – [(rn – 1) – {(rn – 1) – (N – M)}]= – [rn – 1 – rn+ 1+
(N – M)]= – (N – M)
Fall 2022 20
Subtraction using 9’s Complement
• You can use the 9’s complement for performing subtraction.
• You can add the minuend M to the 9’s complement i.e (r-1)’s
complement of subtrahend N. Then inspect the result.
If an end carry occurs discard end carry by – rn , and add 1 to the
least significant digit i.e end around carry
If there is no end carry take 9’s complement i.e (r-1)’s
complement of the result obtained and place a negative sign
Note: Remember that 9’s complement is 1 less than 10’s
complement. This means we must compensate by adding 1
when an end carry occurs. Removing an end-carry and adding
one is called an end-around carry.
Fall 2022 21
9’S Complement Subtraction Example
• Using 9’s complement, subtract 62513– 2140
M= 62513
9’S complement of N=+ 97859
SUM 160372
– rn -100000
60372
end around carry +1
Answer= 60373
Fall 2022 22
9’S Complement Subtraction Example
• Using 9’s complement, subtract 2140 – 62513
M= 02140
9’S complement of N=+ 37486
SUM 39626
No end around carry;
9’s complement 60373
(Add – Sign) Answer= -60373
Fall 2022 23
Subtraction using 1’s Complement
• You can also use the 1’s complement for performing subtraction.
• You can add the minuend M to the 1’s complement i.e (r-1)’s
complement of subtrahend N. Then inspect the result.
If an end carry occurs discard the end carry by – rn and add 1 to
the least significant digit i.e end around carry.
If there is no end carry take 1’s complement i.e (r-1)’s
complement of the result obtained and place a negative sign
Note: Remember that 1’s complement is 1 less than 2’s
complement. This means we must compensate by adding 1
when an end carry occurs. Removing an end-carry and adding
one is called an end-around carry.
Fall 2022 24
1’s Complement Subtraction
• Using 1’s complement, subtract 1001001 - 1000110
Fall 2022 25
1’s Complement Subtraction
• Using 1’s complement, subtract 1000110 - 1001001
Fall 2022 26
Your Turn
Fall 2022 27
The End
Fall 2022 28