CPE 315
Prof. Stearns
Why Two's Complement?


Wikipedia page

Early computers represented both positive and negative integers in a binary word.
But addition/subtraction hardware was quite complex and slow.

Two's complement notation was adopted to:

  1. Reduce the size/complexity of the adder circuit
  2. Improve the performance of the adder circuit
  3. Eliminate the need for subtraction hardware
  4. Eliminate negative integers
That's right:
Modern CPUs don't have negative integers!

Assuming an 8 bit (numbers 00 to FF) ALU, here's how two's complement works.
Numbers 00-7F retain their normal positive values.
Numbers 80-FF are designated as negative numbers; it's critical to note the adder hardware doesn't know this!

An example:

    FF
   +01
    __
    00
By inspection, FF must be a -1.
Try to avoid saying FF == -1; it's much better to realize that FF is designated as -1.

Another example:

    A5
   +xx
    __
    00
Some questions:
What is xx? in hex? in decimal?
What is A5 in decimal?
How does one compute -A5 = xx?

Important Note: two's complement is not a verb nor an operation.
Avoid saying: "take the two's complement"
It is much better to say: "negate"

Like all abstractions, two's complement notation has some side-effects.
  1. -80 == 80
    There exists a number that can't be negated correctly.
  2. Subtraction carry bit
    There is no hardware subtraction.
    A-B is calculated by adding A+(-B) but that operation calculates the carry bit incorrectly.

Last updated on 1/6/07