module demux1to4 (
input d,
input [1:0] s,
output [3:0] y
);
// One-hot mask (1 << s), then gate with d replicated across 4 bits.
assign y = ({4{d}}) & (4'b0001 << s);
endmodule
case version (Behavioral)module demux1to4 (
input d,
input [1:0] s,
output reg [3:0] y
);
always @* begin
y = 4'b0000;
case (s)
2'b00: y[0] = d;
2'b01: y[1] = d;
2'b10: y[2] = d;
2'b11: y[3] = d;
endcase
end
endmodule
({4{d}} & (1 << s)) builds a one-hot at index s and drives it with d.always @*, always give defaults to avoid unintended latches.casez and decide what to drive on unknowns (often y = 4'bxxxx;); beginners can stick with plain case and clean inputs.