BCD addition: 25 + 48

corethe +6 correction

Answer

01110011 = 73

Why this example is worth doing

Five plus eight is thirteen, which does not exist as a BCD digit, so the low nibble lands in the illegal range and must be corrected by adding six — pushing it past the six wasted patterns and generating the decimal carry as a side effect. The page shows the uncorrected intermediate, the detection condition and the corrected result, because the intermediate is where the marks are and it is invisible in the final answer.

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 00100101 + 01001000

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 00100101 + 01001000
digitraw sum5-bit> 9?nibble carrycorrectiondigitcarry out
12 + 4 + 1 = 700111no0-0111 (7)0
05 + 8 + 0 = 1301101yes0+01100011 (3)1

result0111 001173

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 (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