
Decimal to Two's Compliment Conversion
These examples show conversion of a decimal number to 8-bit twos
compliment. The bit size is always important with twos
compliment, since you must be able to tell where the sign bit is.
The steps are simple. First, you convert the magnitude of the
number to binary, and pad to the word size
(8 bits). If the original number was positive, you are done.
Otherwise, you must negate the binary number by inverting the bits
and adding 1.
- Convert -72 to an 8-bit, twos compliment binary number.
- Convert the magnitude, 72 to binary. The easiest way is to
convert it to hex first. 72÷16 = 4 remainder 8, so
7210 = 4816 = 10010002.
- Pad to 8 bits: 01001000
- Negate the number by inverting the bits and adding 1.
| 0 | 1 | 0 | 0 | 1 | 0 | 0 | 0 |
| ¬ |
1 | 0 | 1 | 1 | 0 | 1 | 1 | 1 |
| + | | | | | | | | 1 |
| 1 | 0 | 1 | 1 | 1 | 0 | 0 | 0 |
So, -7210 is 10111000 as an eight-bit, two's compliment number.
- Convert 47 to an 8-bit, twos compliment binary number.
This is positive, so all that is needed is to convert to binary and
pad to eight bits. 47÷16 = 2 remainder 15, so
4710 = 2f16 = 1011112.
So 47 as an 8-bit two's compliment number is
just 00101111.
- Convert -109 to an 8-bit, twos compliment number. Again, the
magnitude: 109÷16 = 6 remainder 13, so
10910 = 6d16 = 11011012.
| 0 | 1 | 1 | 0 | 1 | 1 | 0 | 1 |
| ¬ |
1 | 0 | 0 | 1 | 0 | 0 | 1 | 0 |
| + | | | | | | | | 1 |
| 1 | 0 | 0 | 1 | 0 | 0 | 1 | 1 |
- Convert -67 to an 8-bit, twos compliment number.
67÷16 = 4 remainder 3, so
6710 = 4316 = 10000112.
| 0 | 1 | 0 | 0 | 0 | 0 | 1 | 1 |
| ¬ |
1 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
| + | | | | | | | | 1 |
| 1 | 0 | 1 | 1 | 1 | 1 | 0 | 1 |
- Convert 81 to an 8-bit, twos compliment number.
Since this is positive, it's just a matter of
converting to binary and padding to 8 bits.
81÷16 = 5 remainder 1, so
8110 = 5116 = 10100012, giving 01010001.