Priority Encoder Simulator
Simulate 4-to-2 and 8-to-3 priority encoders online. Toggle multiple digital inputs, choose highest-input or lowest-input priority, and calculate the encoded binary output, decimal input index and valid signal.
—
PRIORITY
ENCODER
—
—
Priority Encoder Simulator
The Priority Encoder Simulator models digital priority encoders that convert one active input line into a shorter binary code. Unlike an ordinary encoder, a priority encoder can handle multiple active inputs by assigning one input higher priority than another.
This simulator supports both the common 4-to-2 priority encoder and an 8-to-3 priority encoder. You can activate several inputs simultaneously and see which input wins according to the configured priority direction.
The simulator also provides a valid output V. The valid signal indicates whether at least one encoder input is active, which removes the ambiguity between a genuine encoded zero and the state where no input is present.
How to Use the Priority Encoder Simulator
Choose either a 4-to-2 or 8-to-3 priority encoder. Click the individual input buttons to toggle them between 0 and 1, choose the priority direction and then press Simulate Priority Encoder.
4-to-2 encoder
Inputs:
I3 = 0
I2 = 1
I1 = 1
I0 = 0
Priority:
Highest index
I2 overrides I1.
Winning input:
I2
Encoded output:
10
Valid:
1What Is a Priority Encoder?
A priority encoder is a combinational digital circuit that detects the highest-priority active input and outputs a binary number identifying that input.
For example, a four-input priority encoder needs only two output bits because two binary bits can represent four input indices from zero through three.
Input index → binary code
I0 → 00
I1 → 01
I2 → 10
I3 → 114-to-2 Priority Encoder
A 4-to-2 priority encoder contains four data inputs and two encoded output bits. In the common highest-index-priority convention, I3 has the highest priority and I0 the lowest.
Priority order:
I3
↓
I2
↓
I1
↓
I0If I3 and I1 are both active, the output represents I3 because the higher-priority input suppresses the lower one.
4-to-2 Priority Encoder Truth Table
X represents a don’t-care input because once a higher-priority input is active, lower-priority inputs no longer affect the encoded result.
| I3 | I2 | I1 | I0 | Y1 | Y0 | V | Winning Input |
|---|---|---|---|---|---|---|---|
| 1 | X | X | X | 1 | 1 | 1 | I3 |
| 0 | 1 | X | X | 1 | 0 | 1 | I2 |
| 0 | 0 | 1 | X | 0 | 1 | 1 | I1 |
| 0 | 0 | 0 | 1 | 0 | 0 | 1 | I0 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | None |
Why Does a Priority Encoder Need Priority?
An ordinary encoder assumes that only one input is active at a time. If several ordinary encoder inputs become active simultaneously, the result may be ambiguous or invalid.
A priority encoder removes this ambiguity by defining which input wins. Therefore multiple high inputs still produce one deterministic encoded output.
Inputs:
I3 = 0
I2 = 1
I1 = 1
I0 = 1
Highest-priority mode:
Winner:
I2
Output:
10Valid Output in a Priority Encoder
A valid output is commonly included because encoded zero can otherwise mean two different things.
Case 1:
I0 = 1
All others = 0
Encoded output:
00
V = 1
Case 2:
All inputs = 0
Encoded output:
00
V = 0The valid bit distinguishes those two situations.
4-to-2 Encoder Example: I3 Active
I3 = 1
I2 = 1
I1 = 0
I0 = 1
Highest-priority input:
I3
Lower active inputs:
I2, I0
Ignored because I3 wins.
Output:
11
Decimal index:
3
Valid:
14-to-2 Encoder Example: I2 Active
I3 = 0
I2 = 1
I1 = 1
I0 = 1
Highest active input:
I2
Output:
10
Valid:
1I1 and I0 are don’t-care conditions once I2 is active and I3 is zero.
8-to-3 Priority Encoder
An 8-to-3 priority encoder accepts eight input lines and produces a three-bit output. Three output bits are sufficient because they can encode decimal input indices zero through seven.
I0 → 000
I1 → 001
I2 → 010
I3 → 011
I4 → 100
I5 → 101
I6 → 110
I7 → 1118-to-3 Priority Encoder Example
Inputs:
I7 = 0
I6 = 0
I5 = 1
I4 = 0
I3 = 1
I2 = 0
I1 = 1
I0 = 0
Highest-priority mode:
Winner:
I5
Encoded output:
101
Decimal:
5
Valid:
1Highest-Priority vs Lowest-Priority Encoding
Most priority encoder examples assign the highest numbered input the greatest priority. This simulator also includes lowest-index priority so you can study the opposite convention.
Active inputs:
I3, I1
Highest-index priority:
I3 wins
Output = 11
Lowest-index priority:
I1 wins
Output = 01The encoded number always represents the winning input; only the rule used to choose that winner changes.
Priority Encoder vs Ordinary Encoder
| Feature | Ordinary Encoder | Priority Encoder |
|---|---|---|
| Multiple active inputs | Usually invalid or ambiguous | Resolved by priority |
| Encoded output | Active input index | Highest-priority active input |
| Priority logic | No | Yes |
| Valid signal | Optional | Common |
Priority Encoder vs Decoder
An encoder performs the opposite conceptual transformation of a decoder. An encoder converts one of many input lines into a compact binary code, while a decoder expands a compact binary code into one of many output lines.
Encoder:
8 input lines
↓
3-bit code
Decoder:
3-bit code
↓
8 output linesPriority Encoder Boolean Logic
For a standard active-high 4-to-2 priority encoder where I3 has the highest priority, the winning conditions can be written as:
I3 wins when:
I3 = 1
I2 wins when:
NOT I3 AND I2
I1 wins when:
NOT I3 AND NOT I2 AND I1
I0 wins when:
NOT I3 AND NOT I2 AND NOT I1 AND I0These conditions show how each higher-priority input suppresses every lower-priority input.
Encoded Output of a 4-to-2 Priority Encoder
Once the winning input has been identified, the encoder outputs its binary index.
Winner I0:
index 0
binary 00
Winner I1:
index 1
binary 01
Winner I2:
index 2
binary 10
Winner I3:
index 3
binary 11What Happens When No Input Is Active?
If every input is zero, there is no valid input to encode. The encoded bits are normally shown as zero by this simulator, while the valid signal V becomes zero.
I3 I2 I1 I0
0 0 0 0
Code:
00
Valid:
0
Meaning:
No active inputAlways inspect the valid output instead of assuming code 00 means I0.
Why Input Index Is Converted to Binary
An encoder reduces the number of signal lines by representing the active input number as a binary value.
4 possible inputs:
requires log2(4) = 2 output bits
8 possible inputs:
requires log2(8) = 3 output bits
16 possible inputs:
requires log2(16) = 4 output bitsThis makes encoders useful whenever many mutually related signals need to be represented efficiently.
Priority Encoders in Interrupt Systems
One common conceptual use of priority encoding is interrupt handling. Several devices may request processor attention simultaneously, but the system may need to service the most important request first.
Requests:
IRQ7 = 0
IRQ6 = 1
IRQ5 = 1
IRQ4 = 0
If higher index means higher priority:
IRQ6 wins.
Encoded interrupt number:
110Real interrupt controllers may include additional masking, nesting and control logic, but priority encoding captures the central selection idea.
Priority Encoders in Digital Systems
Priority encoders appear in interrupt controllers, arbitration circuits, keyboard encoding, request handling, event selection and digital control systems.
Whenever several signals can become active at the same time but only one must be represented or serviced, priority encoding provides a deterministic selection rule.
Priority Encoder in Keyboard Encoding
An encoder can convert one of several key lines into a smaller binary code. Priority logic becomes useful when multiple key signals occur simultaneously and the circuit must decide which key receives precedence.
8 possible input keys
↓
8-to-3 encoder
↓
3-bit key numberPriority Encoder and Arbitration
Arbitration circuits decide which request gains access to a shared resource. A fixed-priority encoder can select the highest-ranked active request.
Requests:
R3 = 1
R2 = 0
R1 = 1
R0 = 1
Fixed highest priority:
R3 wins.More advanced arbiters may rotate priority for fairness, but a fixed priority encoder is a basic building block.
Active-High Priority Encoder
This simulator uses active-high logic. An input value of 1 means that the corresponding request is active.
Active-high:
1 = active
0 = inactiveSome physical encoder ICs use active-low inputs or outputs. Their truth tables look inverted and should not be confused with the active-high model used here.
Active-High vs Active-Low Priority Encoders
| Logic Type | Active State | Inactive State |
|---|---|---|
| Active High | 1 | 0 |
| Active Low | 0 | 1 |
Always check the logic convention when comparing a simulator with a particular hardware data sheet.
Common Priority Encoder Mistakes
A common mistake is treating a priority encoder like an ordinary encoder and assuming only one input may be active. Multiple active inputs are specifically what priority logic is designed to resolve.
Another mistake is reading the encoded output without checking the valid bit. Code 00 can represent I0 when I0 is active, but it can also appear when no input is active if V is zero.
It is also important to know which direction has priority. In the standard configuration used by default here, the highest numbered active input wins.
Priority Encoder Simulator Limitations and Notes
This simulator models ideal active-high combinational logic. It supports 4-to-2 and 8-to-3 priority encoders with either highest-index or lowest-index fixed priority.
The simulator does not model propagation delay, active-low IC behavior, tri-state outputs, enable pins, cascading signals or hardware-specific electrical characteristics.
If multiple inputs are active, exactly one winning input is selected according to the configured priority rule.