Representing Negative Integers in Binary
The algorithm just presented works only for positive integers (and zero).
To convert the representation of a negative integer from decimal to binary:
- Use the algorithm with the positive version of the integer (its absolute value).
- Decide how many bits you need in the final representation.
- Usually this will be 8, 16, 24, or 32.
- Put enough zero-bits on the left of the bits from step one to get the total number of bits you need.
- Form the two's compliment of the binary result.
- This is the "reflect, add one" procedure from chapter 8
Let us represent -85 in binary using 8-bit two's compliment.