The issue with the binary system is that there is no way to represent negative numbers, here we will introduce 3 systems designed to solve that problem:

  1. Sign-and Magnitude
  2. 1s Complement
  3. 2s Complement

Signed-and-Magnitude

Use the first bit to represent the sign.

  • 0 for + (positive)
  • 1 for - (negative) For example,
  • 00110100 represents 52
  • 10110100 represents -52

Given n-bits, the range of value it can represent is:

1s Complement

  • Represent the negation of a positive binary value as
  • Or, can think of it as β€œflipping” the binary numbers around
  • e.g. negation of 00001100 is 11110011, representing 1210 and -1210 respectively

Given n-bits, the range of value it can represent is:

2s Complement

  • Represent the negation of a positive binary value as
  • Or, can think of it as β€œflipping” the binary numbers around, then add 1
    • Alternatively, (from LSB to MSB), copy the numbers to the first 1, and invert the rest.
  • e.g. negation of 00001100 is 11110100, representing 1210 and -1210 respectively

Given n-bits, the range of value it can represent is:

Note

You can also extend the idea of complement on fractions!

Excess Representation

  • Allows range of values to be distributed evenly between the positive and negative values.
  • E.g. Excess-4 representation on 3-bits number

Actual value = Bit pattern (unsigned) - 4

3-bit patternUnsigned valueActual value (Excess-4)
0000–4
0011–3
0102–2
0113–1
10040
1015+1
1106+2
1117+3