Part of Curriculum: Verilog Fundamentals (Module 6: Encoders & Decoders)
View Full Roadmap →
Level 1 Easy ★ Flagship #9 15 pts ✓ Solved

2-to-4 Decoder — Binary Decoding

Combinational Logic · combinational, logic-gates, easy, multiplexers-&-decoders

Implement a 2-to-4 active-high binary decoder with an active-high enable input.

Write a synthesizable Verilog module named top_module matching the ports below exactly.
📐 Circuit Schematic Diagram
in[1:0]enableout[3:0]2-TO-4 DECODERDIGITAL HARDWARE BLOCK
⚡ Timing & Synthesizability Constraints

Timing Contract: Combinational delay from address/enable to one-hot output.

RTL Constraints: When enable is 0, all 4 outputs must be 0.

Objective: Understand address decoding, one-hot assertion, and enable gating.

Prerequisites: Binary numbers, bit shifting, one-hot encoding.
NameDirWidthDescription
ininput22-bit binary address input
enableinput1Active-high master enable
outoutput44-bit one-hot decoded output
Expected Waveform (Golden Timing Contract)
💡 Need Guidance? Progressive Hints (3 Levels)
Hint 1: Conceptual Direction & Hardware Primitives
A decoder asserts exactly one line out of $2^N$ based on binary code.
Hint 2: Implementation Architecture & Approach
You can use left shift: `(4'b0001 << in)` shifts the active-1 bit to the exact index `in`.
Hint 3: Edge Cases, Timing & Verilog Syntax
Guard with `enable`: `assign out = enable ? (4'b0001 << in) : 4'b0000;`.
🔒 Reveal Verified Reference RTL Solution (Click to expand)
⚠️ Self-Discovery Warning: Try solving and simulating first! Viewing the verified reference implementation will bypass the real debugging experience.
Verified Synthesizable RTL
module top_module(
  input        [1:0] in,
  input              enable,
  output       [3:0] out
);
  assign out = enable ? (4'b0001 << in) : 4'b0000;
endmodule
Verilog-2001 / SV Saved
Font: |
// Click Run Tests (or press Ctrl+Enter) to compile your RTL and simulate against hidden testbenches.
Simulation Timing Diagram (VCD Waveform)
100%
No simulation waveform yet. Run tests to simulate and generate VCD traces.
No compilation run yet. Syntax warnings and elaboration messages will appear here.
No simulation output yet. Raw stdout from vvp will appear here.

RTL Problems / Level 1 · Combinational Logic

What You Will Learn

By solving 2-to-4 Decoder — Binary Decoding, you will acquire core industry skills:

  • Synthesizable hardware modeling in standard Verilog-2001 / SystemVerilog.
  • Correct handling of interface port contracts, edge-triggered clocks, and active-low/high resets.
  • Simulation waveform interpretation and debugging using timing diagrams (VCD traces).
  • Architectural avoidance of timing violations, glitching hazards, and synthesis warnings.

Problem Statement & Requirements

Implement a 2-to-4 active-high binary decoder with an active-high enable input.

Hardware design teams at leading semiconductor firms evaluate these exact port contracts, race-condition assertions, and corner cases during technical design reviews and ASIC engineer interviews.

Objective: Understand address decoding, one-hot assertion, and enable gating.

Prerequisites: Binary numbers, bit shifting, one-hot encoding.

Port List & Interface Timing

The hidden testbench instantiates top_module. Module port names and bit-widths must match the interface contract exactly:

NameDirWidthDescription
ininput22-bit binary address input
enableinput1Active-high master enable
outoutput44-bit one-hot decoded output

Timing Constraints & Synthesizable RTL Rules

⚡ Synthesizable Implementation Guidelines

Timing Contract: Combinational delay from address/enable to one-hot output.

Synthesis Constraints: When enable is 0, all 4 outputs must be 0.

Architectural Deep Dive & Implementation Walkthrough

A 2-to-4 binary decoder converts a 2-bit address into four mutually exclusive select signals. Decoders form the core of SRAM wordline selectors, register file write-enable decoders, and memory-mapped peripheral address decoders.

Common RTL Designer Pitfalls

⚠️ Common Mistakes to Avoid

['Forgetting to check `enable`: output must be all 0s when `enable = 0`.', 'Inverting bit endianness: confusing `out[0]` with `out[3]`.']

Silicon & Hardware Engineering Notes

🛠️ ASIC vs FPGA Hardware Considerations

In standard cell libraries, decoders with enable inputs are often implemented as NAND gates with active-low outputs followed by inverters, matching standard memory block select interfaces.

Starter RTL Code

module top_module(
  input        [1:0] in,
  input              enable,
  output       [3:0] out
);

  // Decode 2-bit binary to 4-bit one-hot when enable=1

endmodule

Verified Reference Solution

🔒 Reveal Verified Reference RTL Solution
module top_module(
  input        [1:0] in,
  input              enable,
  output       [3:0] out
);
  assign out = enable ? (4'b0001 << in) : 4'b0000;
endmodule
Advertisement

Related RTL Problems in Level 1

Frequently Asked Questions

What does 2-to-4 Decoder — Binary Decoding require?

Implement a 2-to-4 active-high binary decoder with an active-high enable input. Implement it as Verilog module top_module matching the listed ports.

Is this design combinational or sequential?

Tags: combinational, logic-gates, easy, multiplexers-&-decoders. If a clock signal is present in the port table, implement it as sequential logic; otherwise, use continuous assignments or combinational blocks.

How is my solution graded?

A hidden SystemVerilog testbench simulates your module in the cloud judge. You pass when all directed corner cases match the golden model and the VCD timing waveform matches the contract.

How does this challenge help with semiconductor interviews?

Technical interviewers at NVIDIA, Qualcomm, Apple, and Intel routinely ask candidates to code, debug, and explain the timing waveforms of 2-to-4 Decoder — Binary Decoding to assess real-world synthesizability and race-condition awareness.

Advertisement