Prev Problem
Next Problem

67. Decoder

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

//==================================================
// Module: decoder3to8
// Description: 3-to-8 Decoder (one-hot output)
//==================================================

module decoder3to8 (
    input  wire [2:0] s,
    output reg  [7:0] y
);

    always @* begin
        // Default all outputs to 0
        y = 8'b0000_0000;

        // Activate one-hot line based on select
        case (s)
            3'b000: y = 8'b0000_0001;
            3'b001: y = 8'b0000_0010;
            3'b010: y = 8'b0000_0100;
            3'b011: y = 8'b0000_1000;
            3'b100: y = 8'b0001_0000;
            3'b101: y = 8'b0010_0000;
            3'b110: y = 8'b0100_0000;
            3'b111: y = 8'b1000_0000;
            default: y = 8'b0000_0000;
        endcase
    end

endmodule

 

Was this helpful?
Upvote
Downvote