1’s and 2’s complement of the binary numbers(positive and negative):
Property: Two’s complement representation allows the use of binary arithmetic operations on signed integers, yielding the correct 2’s complement results.
Positive Numbers: Positive 2’s complement numbers are represented as the simple binary.
Negative Numbers: Negative 2’s complement numbers are represented as the binary number that when added to a positive number of the same magnitude equals zero.
| Integer | 2’s Complement | |
| Signed | Unsigned | |
| 5 | 5 | 0000 0101 |
| 4 | 4 | 0000 0100 |
| 3 | 3 | 0000 0011 |
| 2 | 2 | 0000 0010 |
| 1 | 1 | 0000 0001 |
| 0 | 0 | 0000 0000 |
| -1 | 255 | 1111 1111 |
| -2 | 254 | 1111 1110 |
| -3 | 253 | 1111 1101 |
| -4 | 252 | 1111 1100 |
| -5 | 251 | 1111 1011 |
Note: The most significant (leftmost) bit indicates the sign of the integer; therefore it is sometimes called the sign bit.
- If the sign bit is zero, then the number is greater than or equal to zero, or positive.
- If the sign bit is one, then the number is less than zero, or negative.
Calculation of 2’s Complement:
To calculate the 2’s complement of an integer, invert the binary equivalent of the number by changing all of the ones to zeroes and all of the zeroes to ones (also called 1’s complement), and then add one.
For example,
0001 0001(binary 17) 1110 1111(two’s complement -17)
Step1: NOT(0001 0001) = 1110 1110 (Invert bits)
Step2: 1110 1110 + 0000 0001 = 1110 1111 (Add 1)
2’s Complement Addition: Two’s complement addition follows the same rules as binary addition.
For example, 5 + (-3) = 2
0000 0101 = +5
+ 1111 1101 = -3
_________________________
0000 0010 = +2
2’s Complement Subtraction: Two’s complement subtraction is the binary addition of the minuend to the 2’s complement of the subtrahend (adding a negative number is the same as subtracting a positive one).
For example, 7 – 12 = (-5)
0000 0111 = +7
+ 1111 0100 = -12
________________________
1111 1011 = -5
2’s Complement Multiplication: Two’s complement multiplication follows the same rules as binary multiplication.
For example, (-4) × 4 = (-16)
1111 1100 = -4
× 0000 0100 = +4