BitFlow

2-to-4 Decoder

beginner · combinational · 45 XP

Sign in to write your solution, run it in the simulator and submit it for grading.

Sign in or create a free account →

Problem

2-to-4 Decoder A decoder converts a binary address to a one-hot output — exactly one output is active. Inputs: 2-bit `in[1:0]`, 1-bit active-high enable `en`. Output: 4-bit `y[3:0]` (one-hot, active-high). When `en=0`, all outputs are 0. | en | in | y | |----|----|------| | 1 | 00 | 0001 | | 1 | 01 | 0010 | | 1 | 10 | 0100 | | 1 | 11 | 1000 | | 0 | XX | 0000 |

Constraints

  • Use always @(*) with case. Check en first.
  • Default y=4'b0000 to prevent latches.

Examples

Input: en=1, in=2'b10

Output: y=4'b0100

Input: en=0, in=2'b10

Output: y=4'b0000

Common questions

What does the 2-to-4 Decoder problem ask you to build?
2-to-4 Decoder A decoder converts a binary address to a one-hot output — exactly one output is active. Inputs: 2-bit `in[1:0]`, 1-bit active-high enable `en`. Output: 4-bit `y[3:0]` (one-hot, active-high). When `en=0`, all outputs are 0.
What constraints does 2-to-4 Decoder have?
Use always @(*) with case. Check en first.; Default y=4'b0000 to prevent latches.
What is an example input and output for 2-to-4 Decoder?
Input en=1, in=2'b10 gives output y=4'b0100.
Which Verilog concepts does 2-to-4 Decoder practise?
combinational, decoder, case, always, enable.