previous | start | next

Two's complement - Summary

1. For a signed integer, b, -b is usually represented at the bit level
   as the two's complement of b.
2. The two's complement of b can be computed as ~b + 1; that is, add 1
   to the 1's complement.
3. The "leftmost" bit of most significant byte of an signed integer in
   two's complement is the sign bit. A sign bit of 0 means a value
   >= 0; a sign bit of 1 means a negative value.
4. At the bit level, all operations on signed integers using two's
   complement to represent negative values are computed the same way
   as for unsigned integers except possibly right shift.
5. Right shift for signed integers using two's complement to represent
   negative values typically uses arithmetic right shift. This
   means that the leftmost empty bits are filled with the sign bit. So
   the result of an arithmetic right shift of a negative value remains
   negative; right shift of a postive value remains positive.
6. Logical right shift of a signed integer fills the leftmost empty
   bits with 0's. So the result of a logical right shift of a negative
   value can be positive.


previous | start | next