Decimal to BCD encoder: 10 inputs to 4 bits, live
A decimal to BCD encoder turns one active input out of ten, D0 to D9 (a key on a keypad, say), into the 4-bit BCD code of that digit, B3 B2 B1 B0. Each output ORs the inputs whose digit has that bit set: B0 = D1 + D3 + D5 + D7 + D9, B1 = D2 + D3 + D6 + D7, B2 = D4 + D5 + D6 + D7 and B3 = D8 + D9.
It is the decimal cousin of the 8-to-3 encoder, and the reverse of the BCD to decimal decoder. D0 is not wired to anything, because its code is 0000, which is also what the outputs show when no key is pressed; a practical keypad encoder adds a valid output to tell the two apart. Like every plain encoder, it assumes one input at a time: press 3 and 5 together and it outputs 0111, a 7. Chips such as the 74147 are priority encoders instead, where the highest pressed key wins (see the priority encoder). All 1,024 input combinations are checked against the OR equations before the page is built.
Open this circuit in the lab →
What you need
- 4× OR: B0 = D1 OR D3 OR D5 OR D7 OR D9
- 3× OR: B1 = D2 OR D3 OR D6 OR D7
- 3× OR: B2 = D4 OR D5 OR D6 OR D7
- 1× OR: B3 = D8 OR D9
Step by step
- Place inputs
D9toD0and probesB3toB0. - For each output bit, list the digits 1 to 9 whose BCD code has that bit set.
- OR those inputs together: five for B0, four each for B1 and B2, two for B3. D0 needs no gate.
- Turn on one input at a time: the outputs show its digit in BCD.
Decimal to BCD encoder truth table
| Active input | B3 | B2 | B1 | B0 |
|---|---|---|---|---|
| D0 | 0 | 0 | 0 | 0 |
| D1 | 0 | 0 | 0 | 1 |
| D2 | 0 | 0 | 1 | 0 |
| D3 | 0 | 0 | 1 | 1 |
| D4 | 0 | 1 | 0 | 0 |
| D5 | 0 | 1 | 0 | 1 |
| D6 | 0 | 1 | 1 | 0 |
| D7 | 0 | 1 | 1 | 1 |
| D8 | 1 | 0 | 0 | 0 |
| D9 | 1 | 0 | 0 | 1 |
The table assumes exactly one input is 1. With more than one, each output is the OR of their codes, which is why real keypads use a priority encoder.
You can also read the full theory in the lesson on BCD. 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 decimal to BCD encoder in the lab →Frequently asked
What is a decimal to BCD encoder?
A circuit with ten inputs, one per decimal digit, and four outputs that give the BCD code of the active input. It is also called a 10-to-4 line encoder.
How many OR gates does a decimal to BCD encoder need?
Four OR gates with up to five inputs: one per output bit. With 2-input gates it takes eleven, as here.
What is the 74147?
A 10-line to 4-line priority encoder chip (TI lists its SN74147 as obsolete). It has nine active-low data inputs, with 0 implied when none is active, and encodes only the highest-order active line. This page builds the simpler non-priority version.
Why is D0 not connected?
Its code is 0000, so it never needs to raise an output. The catch is that 0000 also appears when no input is active, which is why practical encoders add a valid output.