Two's Complement

A common way of representing signed integers (can be positive or negative) in computers. You can invert the sign of any number (except 0) by taking the complement of the number and adding 1.

For example using 4 bits:

  • 1011 is the binary representation of -5
  • The complement is 0100 (flip 1s to 0 and 0 to 1)
  • Adding 1 to the complement is 0101
  • 0101 is the binary representation of 5