Tuesday 30 September 2014

• Complements • Subtraction using complements.



• Complements
• Subtraction using complements.

By the end of this class you should be able to:

• Obtain the r’s and (r-1)’s complements in decimal, binary,
and any other number system
• Perform subtraction by addition of the complements


Decimal number complements:

9’s complement of the decimal number N = (10n
 – 1) – N
= n (9’s) – N
i.e. {subtract each digit from 9}

Example Æ 9’s complement of 134795 is 865204
Similarly

1’s complement of the binary number N = (2n
 -1) – N = n (1’s) – N
Example Æ 1’s complement of 110100101 is 001011010
which can be obtained by replacing each one by a zero and each
zero by one.

r’s complement: EE200(class 2-2) Prof. M.M. Dawoud 2of 5
10’s complement of the decimal number N = 10n
 – N = (r-1)’s
complement + 1

Example Æ 10’s complement of 134795 is 865205


Example Æ find the 9’s and 10’s complements of 314700.

Answer Æ 9’s complement = 685299
 10’s complement=685300

Rule: To find the 10’s complement of a decimal number leave all
leading zeros unchanged. Then subtract the first non-zero digit
from 10 and all the remaining digits from 9’s.

The 2’s complement of a binary number is defined in a similar
way.

Example: Find the 1’s and 2’s complements of the binary
number 1101001101

Answer Æ 1’s complement is 0010110010
 2’s complement is 0010110011

Example: Find the 1’s and 2’s complements of 100010100

Answer Æ 1’s complement is 011101011
 2’s complement is 011101100

Subtraction using r’s complement:

To find M-N in base r, we add M + r’s complement of N

Result is M + (rn
 – N)

1) If M > N then result is M – N + rn (rn is an end carry and
can be neglected.
 EE200(class 2-2) Prof. M.M. Dawoud 3of 5
2) If M < N then result is rn
 –(N-M) which is the r’s complement
of the result.

Example: Subtract (76425 – 28321) using 10’s complements.


Answer Æ 10’s complement of 28321 is 71679

 Then add Æ 7 6 4 2 5
 + 7 1 6 7 9

 1 4 8 1 0 4

Therefore the difference is 48104 after discarding the end carry.


Example: subtract (28531 – 345920)

Answer Æ It is obvious that the difference is negative. We
also have to work with the same number of digits, when dealing
with complements.

 10’s complement of 345920 is 654080

 Then add Æ 0 2 8 5 3 1
 + 6 5 4 0 8 0

 6 8 2 6 1 1
Therefore the difference is negative and is equal to the 10’s
complement of the answer.
 Difference is Æ - 317389

The same rules apply to binary.

Example: subtract (11010011 – 10001100)

Discard
No end carry EE200(class 2-2) Prof. M.M. Dawoud 4of 5
Answer Æ 2’s complement of 10001100 is 01110100

Then add Æ 1 1 0 1 0 0 1 1
 + 0 1 1 1 0 1 0 0

 1 0 1 0 0 0 1 1 1
The difference is positive and is equal to 01000111

The same rules apply to subtraction using the (r-1)’s
complements. The only difference is that when an end carry is
generated, it is not discarded but added to the least significant
digit of the result. Also, if no end carry is generated, then the
answer is negative and in the (r-1)’s complement form.


Example: Subtract (76425 – 28321) using 9’s complements.
Answer Æ 9’s complement of 28321 is 71678

 Then add Æ 7 6 4 2 5
 + 7 1 6 7 8

 1 4 8 1 0 3
 1
 4 8 1 0 4



Example: subtract (11010011 – 10001100) using 1’s complement.

Answer Æ 1’s complement of 10001100 is 01110011

Then add Æ 1 1 0 1 0 0 1 1
 + 0 1 1 1 0 0 1 1

 1 0 1 0 0 0 1 1 0
 1

Discard
Difference
Difference EE200(class 2-2) Prof. M.M. Dawoud 5of 5
 1 0 1 0 0 0 1 1 1 

No comments:

Post a Comment