Number systems and error-correcting codes

A computer stores one thing — bits — and every number, character and code in this section is an agreement about what a run of bits means. These ten tools convert between those agreements and show the arithmetic that gets you from one to the other.

Representing numbers

Detecting and correcting errors

The three signed representations

Every one of these tools eventually asks the same question: what does this run of bits stand for? Nowhere is the answer more divided than for negative numbers, where three conventions are all still taught and only one of them is used by machines.

-5 in 8 bits, in the three signed representations.
RepresentationBitsRangeZeros
Sign–magnitude1000 0101-127…127two (0000 0000, 1000 0000)
One's complement1111 1010-127…127two (0000 0000, 1111 1111)
Two's complement1111 1011-128…127one

Only two's complement lets ordinary binary addition work unmodified, which is why every machine you will ever use picks it. One's complement needs an end-around carry — the same mechanism as the Internet checksum. Two’s complement and parity & checksum each show the arithmetic.

Related

  • Boolean & Minimisation

    Turn one expression into every other form of itself, and reduce it with named laws.

  • Gates & Circuits

    What each gate does, in both symbol standards, and how to build circuits out of them.