Is 1010 valid BCD?

coresix wasted patterns per nibble

Answer

invalid — 1010 is one of the six illegal codes

Why this example is worth doing

Four bits have sixteen patterns but decimal needs only ten, so 1010 through 1111 are invalid BCD. The page uses that gap two ways: as the source of BCD's inefficiency — about a sixth of the code space is wasted — and as a free error check, since a nibble in the illegal range means something has gone wrong. It also feeds directly into why BCD addition needs a correction step.

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

Nibble range

A BCD nibble codes 0000…1001. 1010 is 10, outside that range.

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