6.11 Encoder: Converting One Active Input Into a Binary Code
Explain how a simple encoder converts one active input line (out of many) into a compact binary code, and identify the single-active-input assumption that limits a basic encoder's correctness.
An encoder is a combinational circuit that performs the reverse operation of a decoder: it takes a set of input lines, of which normally only one is active at a time, and converts that single active input's position into a compact binary code identifying which input it was. Encoders are the natural circuit to use whenever many individual signal sources need to be compressed down to a small number of wires — for example, converting which one of several keys was pressed on a keypad into a binary code representing that key.
The basic encoding operation
A simple encoder with 2^n input lines produces an n-bit binary output code that identifies which single input is currently active (logic 1). This is the direct inverse of a decoder, which takes an n-bit binary code and activates exactly one of 2^n outputs — an encoder instead takes exactly one active input (out of 2^n) and produces the n-bit binary code identifying its position.
Internally, a simple encoder is typically built from a set of OR gates, one per output bit, each OR gate collecting together every input line whose position has a 1 in that particular output bit position — for example, in an 8-to-3 encoder, the output bit representing the most significant position would OR together every input line numbered 4 through 7, since those are exactly the input positions whose binary index has a 1 in that bit.
Worked structure: 8 inputs to 3-bit output
The spec's canonical example is an 8-to-3 encoder: 8 inputs produce a 3-bit output, since 3 bits are exactly enough to represent 8 distinct positions (2^3 = 8). If input line 5 is the one currently active, the encoder's output should be the 3-bit binary representation of 5, which is 101 — regardless of which specific mechanism (OR-gate network, priority logic, or otherwise) is used internally to produce that code.
This 2^n-inputs-to-n-bit-output relationship mirrors the same power-of-two structure seen throughout this module in multiplexers, demultiplexers, and decoders — it is a recurring pattern in combinational logic design whenever a fixed number of binary select or address lines must uniquely identify one of a larger set of positions.
The critical limitation: only one active input is assumed
A simple encoder's correctness depends entirely on the assumption that exactly one input line is active at any given time. If two or more input lines happen to be active simultaneously, a basic OR-gate-based encoder will produce some combined binary code, but that code will generally not correspond to either of the genuinely active inputs — it becomes an incorrect, ambiguous, or meaningless output, because the simple encoder has no built-in mechanism to decide which of several simultaneously active inputs should 'win' and be reflected in the output code.
This single-active-input assumption is a real and frequently violated constraint in practical systems — for example, on a real keypad, a user might briefly press two keys at almost the same instant, or a fault condition might activate two status lines simultaneously. Whenever multiple inputs can genuinely be active at once, a simple encoder is the wrong tool, and a priority encoder (the next lesson) — which is specifically designed to resolve exactly this ambiguity — must be used instead.
Encoder structure
The 2^n-inputs-to-n-bit-output relationship is the same power-of-two structure used by multiplexers, demultiplexers, and decoders. A basic encoder's output is only meaningful when its single-active-input assumption actually holds.
8 inputs -> 3-bit output (general: 2^n inputs -> n-bit output)
Assumption: exactly one input line is active (logic 1) at any given time.
If input line k is active, output = binary representation of k.Code Examples
This is the spec's own worked example: 8 inputs → 3-bit output. With exactly one input (D5) active, the encoder correctly produces 101, the 3-bit binary code for position 5 — demonstrating the basic encoder's intended, correctly functioning case. Expected result: 101
With exactly one active input at position 5, the encoder's 3-bit output is 101, the binary representation of 5.
This demonstrates the spec's tricky problem directly: a simple encoder assumes only one input is active; if multiple inputs can be active, use a priority encoder. Here, both D4 and D7 being active simultaneously produces an output that only reflects D7, with no indication that D4 was active at all, and no way for downstream logic to detect that an assumption violation even occurred.
A simple encoder cannot correctly report which input was active when more than one input line is active at the same time.
Common mistake: Assuming a basic encoder's output is always trustworthy, without first guaranteeing (elsewhere in the system) that only one input line can ever be active at once.
Inputs D0 D1 D2 D3 D4 D5 D6 D7 = 0 0 0 0 0 1 0 0 (only D5 is active)
Encoder output (3 bits): binary representation of 5 = 101
Check: 101 in binary = 4+0+1 = 5. Matches the position of the single active input, D5.Inputs D0 D1 D2 D3 D4 D5 D6 D7 = 0 0 0 0 1 0 0 1 (both D4 and D8... only D4 and D7 are active)
A simple OR-gate-based encoder ORs together the input lines contributing to each output bit.
With both D4 (binary 100) and D7 (binary 111) active simultaneously, the OR-based output bits
combine contributions from BOTH positions at once, producing 111 (binary 7) --
which incorrectly reports D7 alone, silently losing all information that D4 was also active.8-to-3 encoder block diagram
A basic encoder compresses one active input line's position into a compact binary code, but assumes only one input is ever active.
D0 D1 D2 D3 D4 D5 D6 D7
| | | | | | | |
+--+--+--+--+--+--+--+---> [ Encoder (OR-gate network) ] ---> 3-bit output (identifies the active input)
Correct operation requires exactly one Di to be active (1) at a time.Important Rules
A 2^n-input encoder produces an n-bit binary output identifying which single input is active.
A basic encoder's correctness depends entirely on the assumption that exactly one input is active at a time.
If more than one input can be active simultaneously, a simple encoder's output becomes unreliable or meaningless.
Use a priority encoder instead whenever multiple inputs can genuinely be active at once.
Where encoders are used
Encoders are commonly used to compress a large set of individual status or request signals down to a compact binary code for further processing — converting which of several sensor lines is active into an address for a lookup table, or converting decimal-key-press lines on a numeric keypad into a binary-coded output for a microcontroller. In virtually all of these real applications, the possibility of simultaneous activation (two sensors triggering close together in time, two keys pressed nearly at once) is common enough that a priority encoder, rather than a basic encoder, is the practical default choice.
Using a simple (non-priority) encoder in a system where more than one input line can realistically be active at the same time.
Use a priority encoder whenever multiple simultaneous active inputs are possible, since it is specifically designed to resolve which active input should take precedence.
The spec's tricky problem states this directly: a simple encoder assumes only one input is active; if multiple inputs can be active, use a priority encoder. Ignoring this leads to silently incorrect or ambiguous output whenever the single-active-input assumption is violated.
[tricky] What critical assumption does a simple (non-priority) encoder rely on for correct operation? A. That only one input line is active at any given time B. That all input lines are active simultaneously at all times C. That the output must always be an even number D. That the encoder has more outputs than inputs
A. That only one input line is active at any given time — The spec's tricky problem states this directly: a simple encoder assumes only one input is active. If this assumption is violated by two or more simultaneously active inputs, the encoder's output becomes unreliable, which is precisely why a priority encoder exists as a solution.
For an 8-to-3 encoder, how many output bits are needed, and why? A. 3 bits, since 2^3 = 8 distinct input positions need to be uniquely represented B. 8 bits, one per input line C. 4 bits, to allow for one extra 'no input active' code D. 1 bit, since only one input can be active at a time
A. 3 bits, since 2^3 = 8 distinct input positions need to be uniquely represented — An n-bit binary code can represent exactly 2^n distinct values; since there are 8 possible active-input positions, and 2^3 = 8, exactly 3 output bits are needed and sufficient to uniquely identify which of the 8 inputs is active.
For an 8-to-3 encoder with only input D2 active, determine the 3-bit output, and explain what would happen (informally) if D2 and D6 were both active at once.
With only D2 active, the output is the 3-bit binary representation of 2, which is 010. If D2 (010) and D6 (110) were both active simultaneously, a simple OR-based encoder would combine their bit contributions and produce 110 (binary 6), incorrectly reporting only D6's position while giving no indication that D2 was also active — exactly the kind of ambiguity a priority encoder is built to resolve correctly.
Convert the active input's index to binary for the first part; for the second part, think about which output bits would be set by each active input independently.