Before doing anything, we need to decide if the two’s complement is a positive or negative number.
Firstly you need to look at the most significant bit (the leftmost bit); if it is a 0 then it is positive and simply convert the number to decimal. For example:
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 |
Because the leftmost bit is a 0 then we know the number is positive so we simply add
32 + 4 + 1 = +37.
Negative two’s complement number
If the most significant bit (the leftmost bit); is a 1 then we have to convert the number to a positive number then work out the denary equivalent.
You do this in exactly the same way you converted a positive number to negative i.e.
- invert all the bits (so a 1 becomes a 0 and a 0 becomes a 1)
- then add 1
- convert to denary.
Example
Convert the two’s complement binary number 11111011 to denary.
128 |
64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 | 1 | 1 | 1 | 0 | 1 |
1 |
Because the most significant bit is a 1, we know it is a negative number therefore we need to convert it to a positive number first.
Change all the 1’s to 0 and 0’s to 1.
0 0 0 0 0 1 0 0
Add 1.
0 0 0 0 0 1 0 0
0 0 0 0 0 0 0 1 +
0 0 0 0 0 1 0 1
So 00000101 as Two’s Complement = -5