BCD to Gray code converter: K-map design, live
A BCD to Gray code converter turns the ten BCD digits 0 to 9 into 4-bit Gray code. Using the six unused codes 1010 to 1111 as don't-cares, the K-maps give G3 = B3, G2 = B3 + B2, G1 = B2 XOR B1 and G0 = B1 XOR B0: one OR gate and two XOR gates.
BCD only ever uses the codes 0000 to 1001, so a BCD input never has B3 and B2 (or B3 and B1) both 1. That freedom is what the design uses. A plain binary to Gray converter needs G2 = B3 XOR B2, but on every valid BCD input B3 = 1 only for 8 and 9, where B2 = 0, so B3 XOR B2 and B3 OR B2 always agree, and the K-map with don't-cares picks the simpler OR. G1 and G0 have no don't-cares that help and stay XORs. On the six invalid inputs this circuit's outputs are not Gray code, which is allowed because BCD never produces them. The Gray code converter tool converts any number, and the K-map solver takes don't-cares if you want to repeat the simplification.
Open this circuit in the lab →
What you need
- 1× OR: G2 = B3 + B2 (simplified with don't-cares)
- 2× XOR: G1 = B2 XOR B1, G0 = B1 XOR B0
Step by step
- Place the BCD inputs
B3(most significant) toB0. - Wire B3 straight to
G3. - OR B3 with B2 for
G2: on valid BCD inputs this equals B3 XOR B2. - XOR neighbouring bits for the rest:
G1 = B2 XOR B1,G0 = B1 XOR B0. - Step the input through 0000 to 1001: each Gray output differs from the previous one in a single bit.
BCD to Gray code truth table
| Decimal | BCD B3..B0 | Gray G3..G0 |
|---|---|---|
| 0 | 0000 | 0000 |
| 1 | 0001 | 0001 |
| 2 | 0010 | 0011 |
| 3 | 0011 | 0010 |
| 4 | 0100 | 0110 |
| 5 | 0101 | 0111 |
| 6 | 0110 | 0101 |
| 7 | 0111 | 0100 |
| 8 | 1000 | 1100 |
| 9 | 1001 | 1101 |
| 10 to 15 | 1010 to 1111 | don't care |
The ten valid rows are checked on the live circuit before the page is built. The don't-care rows are the reason G2 can be an OR gate instead of an XOR. Built from four 8-to-1 multiplexers instead: BCD to Gray code converter using 8:1 muxes.
You can also read the full theory in the lesson on Gray code. 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.
More builds: Selecting, routing and decoding
All 246 build guides, by topic
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 to Gray code converter in the lab →Frequently asked
How do you design a BCD to Gray code converter?
Write the truth table for the ten BCD digits, mark the codes 1010 to 1111 as don't-cares, and simplify each output with a K-map. The result is G3 = B3, G2 = B3 + B2, G1 = B2 XOR B1, G0 = B1 XOR B0.
Why is G2 an OR gate and not an XOR?
Because B3 and B2 are never both 1 in a valid BCD digit. For every input that can occur, B3 OR B2 and B3 XOR B2 give the same answer, and the don't-cares let the K-map choose the cheaper OR.
Is BCD to Gray the same as binary to Gray?
For the digits 0 to 9 the outputs are identical, because BCD digits are the binary numbers 0 to 9. The circuits differ only because the BCD version may use the unused codes as don't-cares.
What is 9 in Gray code?
1101. In BCD, 9 is 1001, and the Gray code keeps the top bit and XORs neighbours: 1, 1 XOR 0 = 1, 0 XOR 0 = 0, 0 XOR 1 = 1.