Thiago P.

2's Complement

Written in Computer Science, General CS

← back to the notes


2's Complement is a way of representing negative numbers. It works by

EXAMPLES

 

By using the leftmost bit as a sign flag, the range of possible values goes down.

Also, you'll notice that negative numbers start at -1 (add -1 to the value), so that 1101 looks like it should be -2 but it is actually -2 + -1.

Converting to 2s complement

Convert 0100 to negative 4 in 2s complement

  1. Invert all the bits
    0100 -> 1011
  2. Add 1 to it (-4 + positive 1 = -3)
    1011 -> 1100
  3. Done
    1100 looks like -3 but don't forget that negative numbers in 2s compliment have an extra -1