To represent negative
integers, a method called two's complement is used.
Example
To represent the number -13 as an 8-bit binary number...
Step 1 :
Convert the positive number 13 into an 8-bit binary integer:
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
0 |
0 |
0 |
0 |
1 |
1 |
0 |
1 |
Step 2 :
Change all the bits from 0 to 1 (or from1 to 0.)
128 |
64 |
32 |
16 |
8 |
4 |
2 |
1 |
0 |
0 |
0 |
0 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
0 |
0 |
1 |
0 |
Step 3 : Add 1 - Perform a binary calculation.
1 |
1 |
1 |
1 |
0 |
0 |
1 |
0 |
|
|
|
|
|
|
+ |
1 |
1 |
1 |
1 |
1 |
0 |
0 |
1 |
1 |
Remember when adding in binary that 1 + 1 = 10 etc...
Final answer : -13 in binary (using two's complement notation) is
11110011
|