Complements in Digital Computers
Complements are essential in digital computers for simplifying subtraction operations and performing logical manipulations. In any base system, there are two types of complements: the 's complement and the 's complement. These complements play a significant role in computer arithmetic.
9's Complement and 1's Complement
Definition
Given a number in base with digits, the 's complement of is defined as:
For decimal numbers, and , so the 9's complement of is:
Here, represents a number that consists of a single 1 followed by zeros. For example, with , and . Therefore, the 9's complement of a decimal number is obtained by subtracting each digit from 9.
Example
-
The 9's complement of 5467 is:
-
The 9's complement of 12389 is:
Generalization to Other Bases
For octal (base 8) and hexadecimal (base 16) numbers, the 's complement is obtained by subtracting each digit from 7 or 15 (F in hexadecimal), respectively.
10's Complement and 2's Complement
Definition
The 's complement of an -digit number in base is defined as:
This can be viewed as adding 1 to the 's complement:
Thus, the 10's complement of the decimal number 2389 is:
Similarly, the 2's complement of the binary number 1010 is:
Alternative Formation
For forming the 's complement of , you can leave all the least significant zeros unchanged, subtract the first non-zero least significant digit from , and then subtract all higher significant digits from .
Example
-
The 10's complement of 246700 is obtained by leaving the two zeros unchanged, subtracting 7 from 10, and subtracting the other three digits from 9:
-
The 2's complement of the binary number 11001100 is obtained by leaving the two low-order 0's and the first 1 unchanged, then flipping the other bits:
Subtraction Using Complements
General Procedure
To subtract two -digit unsigned numbers and in base :
-
Add the minuend to the 's complement of the subtrahend :
-
Discard the end carry :
-
If , the sum will produce an end carry , which is discarded, and the result is .
-
If , the sum does not produce an end carry. The result is , which is the 's complement of . To obtain the answer in a familiar form, take the 's complement of the sum and place a negative sign in front.
-
Example
-
Subtraction with :
-
10's complement of 13250 is 86750.
-
Add:
-
Discard the end carry:
-
-
Subtraction with :
-
10's complement of 72532 is 27468.
-
Add:
-
Result is negative since there is no end carry. The 10's complement of 40718 is 59282:
-
Binary Subtraction
Using 2's complement for binary subtraction follows the same principles:
-
Example: and
-
Let and .
-
2's complement of is .
-
Add:
-
Discard the end carry:
-
For :
-
2's complement of is .
-
Add:
-
No end carry, result is negative. The 2's complement of 1101111 is 0010001:
-
-
Handling Radix Points
When numbers contain a radix point, temporarily remove it to form the 's or 's complement. Restore the radix point in the complemented number at the same relative position.
Complement of the Complement
The complement of the complement restores the original number. The 's complement of is . The complement of the complement is:
Subtraction of Unsigned Numbers
The direct method of subtraction using the borrow concept is less efficient in digital hardware compared to using complements. By adding the minuend to the 's complement of the subtrahend , we can simplify subtraction significantly.
Procedure Summary
- Add to the 's complement of .
- Discard the end carry if present.
- If no end carry, the result is the 's complement of the difference, with a negative sign.
This method is highly efficient and preferred for binary arithmetic in digital systems.