An encoder does the opposite of a decoder. It has 2ⁿ input lines and n outputs, and it reports which input is 1 as a binary number.
A plain encoder assumes its inputs are one hot: exactly one line is active. Then each output bit is a single OR gate. Write each input's index in binary and ask which indices set that bit. For a 4-to-2 encoder:
- Y1 (weight 2) is 1 for inputs 2 and 3: Y1 = .
- Y0 (weight 1) is 1 for inputs 1 and 3: Y0 = .
D0 doesn't appear at all, because index 0 is 00.
That simplicity has two blind spots:
- Several active inputs. D1 and D2 together give
11, which wrongly claims D3. - No active input. Nothing active gives
00, exactly the same as "D0 is active".
The priority encoder fixes both: it reports the highest-priority active input, and adds a valid bit V that says whether any input is active at all.
Where it shows up: turning a row of buttons, sensors or interrupt lines into a compact binary code.