decoder_encoder

This commit is contained in:
Jose Luis Montañes Ojados
2026-03-01 01:02:44 +01:00
parent a1a95b50ab
commit 3f0f6f04e3
2 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
/*
Decoder / Encoder
*/
module decoder_3bit (
input [2:0] in,
output [7:0] out
);
assign out = 1 << in;
endmodule
module encoder_3bit(
input [7:0] in,
output reg [2:0] out
);
always @(*) begin
out = 0;
casez(in)
8'b1???????: out = 3'd7;
8'b01??????: out = 3'd6;
8'b001?????: out = 3'd5;
8'b0001????: out = 3'd4;
8'b00001???: out = 3'd3;
8'b000001??: out = 3'd2;
8'b0000001?: out = 3'd1;
8'b00000001: out = 3'd0;
endcase
end
endmodule