BCD addition needing two corrections: 99 + 99

corecorrections cascade

Answer

000110011000 = 198

Why this example is worth doing

Both digit positions overflow, so the correction is applied twice and the carry ripples into a new leading digit. It is the worst case for a BCD adder and the one that shows the correction is not a special case bolted on for one situation but a per-digit rule applied uniformly. The page steps through both nibbles separately so the cascade is visible.

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

BCD addition 10011001 + 10011001

Work least significant digit first. Add the two digits and the carry in. If the raw sum exceeds 9 OR the 4-bit add carried out, add 0110 and carry 1 into the next digit.

Most significant digit first, as it is written on paper — BCD addition 10011001 + 10011001
digitraw sum5-bit> 9?nibble carrycorrectiondigitcarry out
19 + 9 + 1 = 1910011yes1+01101001 (9)1
09 + 9 + 0 = 1810010yes1+01101000 (8)1

result0001 1001 1000198

why 616 - 10 = 6BCD skips the six codes 1010..1111, so a binary carry (weight 16) has to be realigned with a decimal carry (weight 10)

Warning:

Correction applied at digit 0, 1 (counting from the least significant digit).

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