Skip to content
BetterDL

Decoder

Also called: binary decoder, line decoder, n-to-2ⁿ decoder, 2-to-4 decoder, 3-to-8 decoder, 4-to-16 decoder

A combinational circuit with n inputs and 2ⁿ outputs that sets exactly one output to 1: the one whose number matches the input code.

A decoder turns a binary code into "one line per value". With n inputs it has 2ⁿ outputs, Y0 up to Y(2ⁿ − 1). For any input code, exactly the output with that number is 1 and all the others are 0. The outputs are one hot.

Inside, each output is a single AND gate: output Yᵢ is the minterm mᵢ of the inputs. For a 2-to-4 decoder with A as the MSB:

  • Y0 =
  • Y1 =
  • Y2 =
  • Y3 =

Most decoders also have an enable input. When it is inactive, every output is 0. That makes two more uses possible: a decoder with its enable used as a data input is a demultiplexer, and enables let you build big decoders from small ones (decoder expansion).

Where decoders show up:

  • In every memory, an address decoder turns the address into one active word line.
  • Memory systems decode the top address bits into chip select signals.
  • A CPU's control unit decodes the opcode into one line per instruction.
  • Since a decoder supplies every minterm, a decoder plus an OR gate can build any function (decoder implementation).

The reverse job, from one active line back to its code, is done by an encoder.

ABY0Y1Y2Y3

Worked examples

Example

Tracing a 3-to-8 decoder

Inputs A, B, C = 1, 1, 0 (A is the MSB).

  1. 1.

    Read the code: 110₂ = 6.

  2. 2.

    Y6 = = 1 · 1 · 1 = 1.

  3. 3.

    Every other output contains a literal that is 0 here. For example Y7 = has C = 0, and Y2 = has = 0.

  4. 4.

    Outputs Y7…Y0 = 01000000: one-hot, with the 1 in position 6.

Example

Inputs from outputs

A decoder (no enable) has 64 outputs. How many inputs does it have?

  1. 1.

    Outputs = 2ⁿ, so 2ⁿ = 64.

  2. 2.

    64 = 2⁶, so n = 6. It is a 6-to-64 decoder.

Common mistakes

  • Giving a decoder 2n outputs. The count is 2ⁿ: a 4-input decoder has 16 outputs, not 8.

  • Expecting more than one output to be 1. Without an enable, exactly one output is 1 for every input; with the enable off, none is.

  • Mixing it up with an encoder. A decoder goes from a code to one line (few in, many out); an encoder goes from one line to a code (many in, few out).

Practice Decoder

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

Learn it step by step

Decoder is taught in Combinational Logic and Memory.