Basic Encoder
How a one-hot-to-binary encoder works in Verilog, and why it assumes only one input is active at a time.
Updated 2026-07-07
An encoder is the reverse of a decoder: a one-hot input (exactly one active line among several) maps to a compact binary output. A 4-to-2 encoder takes a 4-bit one-hot input and produces a 2-bit binary output identifying which line was active.
A basic encoder assumes exactly one input is active at a time. If more than one input line is active simultaneously, the input pattern does not match any of the case items the encoder lists, so the output falls through to whatever default value was assigned at the top of the block — not a crash, but not a meaningful answer either.
Priority encoders exist specifically to resolve this ambiguity: they define a priority order among the inputs, so a well-defined output is produced even when multiple inputs are active at once. A basic encoder should only be used where the one-active-input assumption genuinely holds.