Computing Library › Digital Logic & Circuits
Digital Logic & Circuits

Decoder

A decoder activates exactly one of its many outputs according to the binary code on its inputs.

What it does

A decoder takes an n-bit input and drives 2^n outputs, asserting exactly the one output whose index equals the input value. A 3-to-8 decoder, for instance, has three inputs and eight outputs, one high at a time.

Logic

Kronos motion — three outputs

Each output is the AND of the input bits in true or complemented form, one product term per minterm. Output Y5 of a 3-bit decoder is A2 AND (NOT A1) AND A0, since 5 is 101 in binary.

Enable input

Most decoders include an enable line. When enable is low all outputs are forced inactive; when high the decoder operates normally. Enable lines let small decoders be combined into larger ones in a hierarchy.

Uses

Decoders select which memory word or device responds to an address, translate instruction opcodes into control signals, and drive displays. Address decoding in memory is one of the most common applications.

In code

python
def decode(value, n):
    outputs = [0] * (2 ** n)
    outputs[value] = 1
    return outputs