4-to-2 encoder: truth table and circuit, live
A 4-to-2 encoder turns one active input out of four, D0 to D3, into its 2-bit binary number Y1 Y0, using two OR gates: Y1 = D2 + D3 and Y0 = D1 + D3. This one adds a valid output V = D0 + D1 + D2 + D3, so you can tell input D0 apart from no input at all.
The encoder is the reverse of a 2-to-4 decoder. Each output bit is the OR of the inputs whose number has that bit set: D2 (10) and D3 (11) have the high bit, D1 (01) and D3 (11) the low bit. D0 encodes as 00, the same as when nothing is pressed, which is what V is for. Here the OR of D2 and D3 does double duty, as Y1 and as half of V, so the whole circuit is four 2-input OR gates. A plain encoder assumes exactly one input is 1. Turn on D1 and D2 together and it outputs 11, a 3 that nobody pressed, because each output just ORs the codes of the active inputs; the live circuit lets you try it. A 4-to-2 priority encoder fixes that by letting the highest-numbered active input win, and the 8-to-3 encoder is the same idea one size up.
Open this circuit in the lab →
What you need
- 1× OR: Y1 = D2 OR D3 (also half of V)
- 1× OR: Y0 = D1 OR D3
- 2× OR: V = (D0 OR D1) OR (D2 OR D3)
Step by step
- Place inputs
D3toD0and probesY1,Y0andV. - Y1: OR together D2 and D3, the inputs whose number is 2 or more.
- Y0: OR together D1 and D3, the odd-numbered inputs.
- V: OR D0 with D1, then OR that with the D2 + D3 gate from Y1.
- Turn on one input at a time: Y1 Y0 spell its number and V is 1. With every input off, V is 0.
4-to-2 encoder truth table
| D3 | D2 | D1 | D0 | Y1 | Y0 | V |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 0 | 1 | 0 | 0 | 1 |
| 0 | 0 | 1 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 0 | 1 | 1 | 1 |
These five rows are the ones an encoder is meant for: no input, or exactly one. The other 11 combinations have two or more inputs on, and the outputs are then the OR of their codes, for example D1 and D2 give 01 OR 10 = 11. All 16 rows of the live circuit are checked against Y1 = D2 + D3, Y0 = D1 + D3 and V = D0 + D1 + D2 + D3 before the page is built. Its opposite, the decoder, is compared in encoder vs decoder.
You can also read the full theory in the lesson on encoders and demultiplexers. 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 4-to-2 encoder in the lab →Frequently asked
What is a 4 to 2 encoder?
A combinational circuit with 4 inputs and 2 outputs that outputs the 2-bit binary number of its one active input: D0 gives 00, D1 01, D2 10 and D3 11.
What are the equations of a 4 to 2 encoder?
Y1 = D2 + D3 and Y0 = D1 + D3, two OR gates. D0 does not appear, because its code is 00. A valid output, V = D0 + D1 + D2 + D3, tells D0 apart from no input.
What happens if two inputs of a 4 to 2 encoder are 1?
A plain encoder outputs the OR of the two codes, which can be a wrong number: D1 and D2 together give 11, the code for D3. A priority encoder avoids this by encoding only the highest-numbered active input.
What is the difference between a 4 to 2 encoder and a 2 to 4 decoder?
They are inverses. The decoder turns a 2-bit number into one active line out of four; the encoder turns one active line back into its 2-bit number.