Two's complement
Two’s complement is a method used by computers to store negative integers in binary. Since binary normally only represents positive numbers, two’s complement allows both positive and negative values to be stored using the same number of bits.
There are two main methods to convert numbers into 8-bit two’s complement (Method 1 is easier).
The binary table headings are written as normal with the exception of the left most bit which should be negative.
Example: Convert -122 into 8-bit two’s complement
|
-128 |
64 | 32 | 16 | 8 | 4 | 2 | 1 |
| 1 | 0 | 0 | 0 | 0 | 1 | 1 |
0 |
- Each column with a 1 is added together
- -128 + 4 + 2
- Answer = -122
This method is a 3 step process
- Write the number as regular binary
- Invert all values in the table
- Add 1 to the binary number
Example: Convert -122 into 8-bit two’s complement
Step 1: Convert 122 into regular 8-bit binary
|
128 |
64 | 32 | 16 | 8 | 4 | 2 | 1 |
| 0 | 1 | 1 | 1 | 1 | 0 | 1 |
0 |
Step 2: Invert each value in the table
| 1 | 0 | 0 | 0 | 0 | 1 | 0 |
1 |
Step 3: Add 1
| 1 | 0 | 0 | 0 | 0 | 1 | 0 | 1 |
| + | 1 | ||||||
| 1 | 0 | 0 | 0 | 0 | 1 | 1 |
0 |
0 + 0 = 0
0 + 1 = 1
1 + 0 = 0
1 + 1 = 10