Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksToolsOpen the lab →

How to build a BCD adder from logic gates

A BCD adder adds two decimal digits stored in BCD (0000 to 1001) plus a carry-in and outputs one BCD digit and a decimal carry. It adds in binary first, and if the binary sum is more than 9 it adds 6 (0110) to skip the six unused codes and sets the carry.

A 4-bit binary adder counts to 15, but a BCD digit stops at 9, so binary sums from 10 to 19 come out wrong as decimal digits. Adding 6 fixes them: it jumps over the six codes 1010 to 1111 and produces the right digit with a carry. The correction is needed exactly when the first adder carries out or its result is 1010 to 1111, which simplifies to Cout = K + Z3 Z2 + Z3 Z1. That Cout is both the decimal carry and the "add 6" signal for a second adder. Every combination of two BCD digits and a carry-in (200 cases) is checked against real decimal addition before the page is built.

Live circuit: click the inputs to toggle them and watch the outputs update. It runs the real simulator, right here on the page.

Open this circuit in the lab →

What you need

Step by step

  1. Place the BCD digits A3 to A0, B3 to B0, and a carry-in Cin. Add them with a 4-bit ripple-carry adder into Z3..Z0 with carry K.
  2. Detect a result over 9: Cout = K OR (Z3 AND Z2) OR (Z3 AND Z1). K covers sums 16 to 19; the two AND terms cover 10 to 15.
  3. Add 0110 when Cout is 1: add Cout into bits 1 and 2 of Z with a second, short adder (bit 0 passes straight through).
  4. Probe the corrected digit as S3 to S0 and the decimal carry as Cout.
  5. Try 0111 + 0101 (7 + 5): the binary sum is 1100 (12), Cout lights, and +6 gives S = 0010 with carry 1, which reads 12 in decimal.

Examples

ABCinBinary sumCorrectedCoutDecimal
0011010101000 (8)100008
0111010101100 (12)0010112
1001100101 0010 (18)1000118
1001100111 0011 (19)1001119
0101010011010 (10)0000110

Inputs above 1001 are not valid BCD digits and are not part of the specification. Chain BCD adders through Cout and Cin to add multi-digit decimal numbers, one digit per stage, which is how calculators and early business computers did decimal arithmetic.

You can also read the full theory in the lesson on binary-coded decimal. Prefer to build it yourself from scratch? Open the digiwleea lab and place the gates on the canvas, or start from the logic gate simulator.

Build more parts from gates

Each of these is one step from a transistor to a working CPU. Build every gate from CMOS transistors and work all the way up in the free digiwleea lab, with the free theory reference alongside.

Open the BCD adder in the lab →

Frequently asked

Why do we add 6 in a BCD adder?

Four bits have 16 codes but BCD uses only 10 of them. When the binary sum is 10 or more, adding 6 skips the six unused codes (1010 to 1111), which leaves the correct decimal digit in the low four bits and produces the decimal carry.

When is the BCD correction needed?

When the binary sum is greater than 9: either the 4-bit adder produced a carry (sums 16 to 19) or the result is 1010 to 1111. The condition is Cout = K + Z3 Z2 + Z3 Z1, where K is the binary carry and Z the binary sum.

How many adders does a BCD adder need?

Two: a 4-bit binary adder for the sum and a second adder that adds 0110 when correction is needed. Because the correction only touches bits 1 to 3, the second adder can be smaller than a full 4-bit adder, as here.

What is the largest sum a one-digit BCD adder handles?

9 + 9 + 1 = 19, which is binary 10011. The correction turns it into digit 1001 (9) with a decimal carry of 1.