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.