Excess-3 code for the digit 5 — BCD

edge casea self-complementing alternative

Answer

1000

Why this example is worth doing

Excess-3 adds three to each digit before encoding, which makes the code self-complementing: the nine's complement of a digit is the bitwise complement of its codeword. That property makes decimal subtraction cheap, which is why excess-3 was used in early calculators. The page includes it to show that 8421 BCD is one choice among several decimal codes, not the only possible one.

Try your own input in the BCD converter. Pack and unpack binary-coded decimal, and add with the +6 correction shown.

How the answer is reached

Excess-3

Excess-3 — columns digit, digit + 3, code
digitdigit + 3code
581000

Compare with

Open the BCD converter

This input is entered in the tool itself — it is too rich for a link to carry.

Note:

Notation this page assumes

  • Bit strings are written most significant bit first, and bit 0 is the least significant bit.
  • A width is stated explicitly wherever it changes the answer; nothing is silently sign-extended or truncated.
  • Fractions are converted digit by digit and shown to a stated number of places rather than rounded silently.

Sources

  • Knuth, The Art of Computer Programming, Vol. 2, §4.1 “Positional Number Systems” (1997)
  • ANSI X3.4 / ISO-IEC 646, the ASCII character set