Skip to content
BetterDL

Encoder

Also called: binary encoder, plain encoder, 4-to-2 encoder, 8-to-3 encoder, 2ⁿ-to-n encoder, non-priority encoder

A combinational circuit with 2ⁿ inputs and n outputs that outputs the binary index of its active input. The reverse of a decoder.

An encoder does the opposite of a decoder. It has 2ⁿ input lines and n outputs, and it reports which input is 1 as a binary number.

A plain encoder assumes its inputs are one hot: exactly one line is active. Then each output bit is a single OR gate. Write each input's index in binary and ask which indices set that bit. For a 4-to-2 encoder:

  • Y1 (weight 2) is 1 for inputs 2 and 3: Y1 = .
  • Y0 (weight 1) is 1 for inputs 1 and 3: Y0 = .

D0 doesn't appear at all, because index 0 is 00.

That simplicity has two blind spots:

  • Several active inputs. D1 and D2 together give 11, which wrongly claims D3.
  • No active input. Nothing active gives 00, exactly the same as "D0 is active".

The priority encoder fixes both: it reports the highest-priority active input, and adds a valid bit V that says whether any input is active at all.

Where it shows up: turning a row of buttons, sensors or interrupt lines into a compact binary code.

D3D2D1D0Y1Y0

Worked examples

Example

An 8-to-3 encoder

Only input D6 is active. Find Y2 Y1 Y0, and the equations.

  1. 1.

    6 = 110, so the output is Y2 Y1 Y0 = 110.

  2. 2.

    Equations: Y2 = (indices with a 4 in them), Y1 = , Y0 = .

  3. 3.

    Check: with only D6 = 1, Y2 = 1, Y1 = 1, Y0 = 0. ✓

Example

Breaking a plain encoder

Feed the 4-to-2 encoder D3 D2 D1 D0 = 0110 (two inputs active).

  1. 1.

    Y1 = = 1 + 0 = 1.

  2. 2.

    Y0 = = 1 + 0 = 1.

  3. 3.

    Output 11 names D3, which isn't even active. The OR gates mixed the codes of D2 (10) and D1 (01).

  4. 4.

    This is why real inputs usually go to a priority encoder.

Common mistakes

  • Giving an encoder more outputs than inputs. It's the other way round: 2ⁿ inputs, n outputs.

  • Trusting a plain encoder with several active inputs. Its output is the OR of their codes, which is usually wrong.

  • Forgetting that "D0 active" and "nothing active" look identical (00) on a plain encoder.

Practice Encoder

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Encoder is taught in Combinational Logic.