Complements are used in computer for the simplification of the subtraction operation. For any number in base r, there exist two complements—(1) r’s complement and (2) r-1 ’s complement.
Number System | Base | Complements Possible |
---|---|---|
Binary | 2 | 1’s complement and 2’s complement |
Octal | 8 | 7’s complement and 8’s complement |
Decimal | 10 | 9’s complement and 10’s complement |
Hexadecimal | 16 | 15’s complement and 16’s complement |
A binary number may be positive or negative. Generally, we use the symbol “+” and “−” to represent positive and negative numbers, respectively. The sign of a binary number has to be represented using 0 and 1, in the computer. An n-bit signed binary number consists of two parts—sign bit and magnitude. The left most bit, also called the Most Significant Bit (MSB) is the sign bit. The remaining n-1 bits denote the magnitude of the number.
In signed binary numbers, the sign bit is 0 for a positive number and 1 for a negative number.
For example, 01100011 is a positive number since its sign bit is 0, and, 11001011 is a negative number since its sign bit is 1. An 8–bit signed number can represent data in the range −128 to +127 (–27to +27−1). The left-most bit is the sign bit.
In an n-bit unsigned binary number, the magnitude of the number n is stored in n bits. An 8–bit unsigned number can represent data in the range 0 to 255 (28 = 256).
1’s Complement of Binary Number is computed by changing the bits 1 to 0 and the bits 0 to 1
Example
» 1’s complement of 101 is 010
» 1’s complement of 1011 is 0100
» 1’s complement of 1101100 is 0010011
2’s Complement of Binary Number is computed by adding 1 to the 1’s complement of the binary number.
Example
» 2’s complement of 101 is 010 + 1 = 011
» 2’s complement of 1011 is 0100 + 1 = 0101
» 2’s complement of 1101100 is 0010011 + 1 = 0010100
The rule to find the complement of any number N in base r having n digits is
(r − 1)’s complement — (rn − 1) − N
(r’s) complement —(rn − 1) − N + 1 = (rn − N)