Skip to content
digiwleeaTools
LearnGlossaryAboutCheat sheetHow a CPU worksBuild a CPUToolsOpen the lab →

Encoder vs decoder: one active line to binary, and back

Encoders and decoders are opposite translators. A decoder takes an n-bit binary input and raises exactly one of its 2^n outputs, the one whose number matches: a 2-to-4 decoder turns 10 into output Y2. An encoder does the reverse: it takes 2^n input lines, one of them active, and outputs that line's number in n bits: a 4-to-2 encoder turns an active input D2 into 10. A plain encoder assumes only one input is active at a time; a priority encoder handles several at once by reporting the highest-numbered one, usually with a valid output that says whether any input is active at all. A decoder expands a number into a choice; an encoder compresses a choice into a number.

What each one is good at

Decoders are how a binary number selects one thing: one memory row from an address, one register to write, one operation from an opcode, one segment pattern for a display. Add an enable input and a decoder becomes a demultiplexer that steers a signal to one of many outputs. Encoders go the other way, turning a set of request or key lines into a compact code: a keyboard row, or a set of interrupt lines into the number of the one to serve, which is the job of a priority encoder.

Build both live in digiwleea

Every one of these runs live in digiwleea, verified against its truth table: the 2-to-4 and 3-to-8 decoders, the decoder with enable and the 1-to-4 demultiplexer it becomes, the 4-to-2 and 8-to-3 encoders, and the priority encoder. The encoders and demultiplexers lesson explains how each is built from gates.

2-to-4 decoder

A1 A0Y0Y1Y2Y3
001000
010100
100010
110001

4-to-2 encoder (one input active)

Active inputY1Y0
D000
D101
D210
D311

No sign-up is needed to start: open the lab and place your first transistor, or read the free theory course. The account (and the AI tutor) are optional.

More comparisons: Digital logic concepts compared

See for yourself: build a logic gate from transistors in the simulator, then follow the path from sand to an 8-bit CPU.

Open the digiwleea lab →

Frequently asked

What is the difference between an encoder and a decoder?

A decoder converts an n-bit binary input into 2^n outputs with exactly one active. An encoder does the reverse: it converts 2^n input lines, one active, into an n-bit binary output.

What is a priority encoder?

An encoder that works when several inputs are active at once by outputting the number of the highest-priority (usually highest-numbered) active input, plus a valid output that is 1 when any input is active.

Is a decoder the same as a demultiplexer?

Nearly: a decoder with an enable input is a demultiplexer when you use the enable as the data input. The selected output then copies the data and the others stay 0.

Where are decoders used?

In memory address decoding (an address selects one row), instruction decoding (an opcode turns on one operation) and display drivers such as BCD to 7-segment decoders.