Digital Logic

Decoder

A combinational circuit that converts a binary input code into a one-hot output, activating exactly one output line.

Detailed Explanation

A decoder with n inputs has 2^n outputs. When the input is binary value k, output k is high and all others are low. This enables address decoding—selecting one of many devices based on an address.

Decoders are used for memory chip select, instruction decoding, demultiplexing, and converting binary-encoded signals to one-hot. Enable inputs allow cascading decoders for larger decode spaces.

Code Example

systemverilog
// 3-to-8 decoder
module decoder_3to8 (
  input  logic [2:0] in,
  input  logic       en,
  output logic [7:0] out
);
  always_comb begin
    out = '0;
    if (en)
      out[in] = 1'b1;
  end
endmodule