Complements
Complements
are used in digital computers for simplifying the subtraction operation and for
logical manipulations. There are two types of complements for each base-r
system: (1) the r’s complement and (2) the (r-1)’s complement. When the value
of the base is substituted, the two types receive the names 2’s and 1’s
complement for binary numbers, 10’s and 9’s complement for decimal numbers.
The
r’s Complement
Given
a positive number N in base r with an integer part of n digits, the r’s
complement of N is defined as rn - N for N is not equal to 0 and 0 for N = 0. The
following numerical example will help clarify the definition.
The
10’s complement of (52520)10 is 105 – 52520 = 47480
The
number of digits in the number is n= 5
The
10’s complement of (0.3267)10 is 1 – 0.3267 = 0.6733
No
integer part, so 10n = 100 = 1
The
10’s complement of (25.639)10 is 102 – 25.639 = 74.361.
The
2’s complement of (101100)2 is 26 – (101100)2
= (1000000 - 101100)2 = 010100
The
2’s complement of (0.0110)2 is (1 – 0.0110)2 = 0.1010
From the
definition and the examples, it is clear that the 10’s complement of a decimal
number can be formed by leaving all least significant zeros unchanged,
subtracting the first nonzero least significant digit from 10, and then
subtracting all other higher significant digits from9. The 2’s complement can
be formed by leaving all least significant zeros and the first nonzero digits
unchanged, and then replacing 1’s by 0’s and 0’s by 1’s in all other higher
significant digits. A third simpler method for obtaining the r’s complement is
given after the definition of the (r-1)’s complement.
The examples listed here use
numbers with r = 10(for decimal) and r = 2(for binary) because these are the
two bases of most interest to us.
The (r
- 1)’s Complement
Given
a positive number N in base r with an integer part of n digits and a fraction
part of m digits, the (r - 1)’s complement of N is defined as rm – r-m
– N. Some numerical examples follow:
The
9’s complement of (52520)10 is (105 – 1 - 52520) = 99999
– 52520 = 47479
No
fraction part, so 10-m = 100 = 1
The 9’s
complement of (0.3267)10 is (1 – 10-4 – 0.3267) = 0.9999
– 0.3267 = 0.6732
No
integer part, so 10n = 100 = 1
The
9’s complement of (25.639)10 is (102 – 10-3 –
25.639) = 99.999 – 25.639 = 74.360
The
1’s complement of (101100)2 is (26 - 1) – (101100) =
(111111 - 101101)2 = 010011
The
1’s complement of (0.0110)2 is (1 – 2-4) – (0.0110) =
(0.1111 – 0.0110)2 = 0.1001
From
the examples, we see that the 9’s complement of a decimal number is formed
simply by subtracting every digit by 9. The 1’s complement of a binary number
is even simpler to form: the 1’s are changed to 0’s and 0’s are changed to 1’s.
Since the (r - 1)’s complement is very easily obtained, it is sometimes
convenient to use it when the r’s complement is desired. From the definitions
and from a comparison of the results obtained in the examples, it follows that
the r’s complement can be obtained from the (r - 1)’s complement after the
addition of r-m to the least significant digit. For example, the 2’s
complement of 10110100 is obtained from the 1’s complement 01001011 by adding 1
to give 01001100.
Short
Trick to find 1’s and 2’s complement in Binary
1’s
complement – Replace 0 by 1 and 1 by 0
2’s
complement – Add 1 after replacing 0 by 1 and 1 by 0
Comments
Post a Comment