FPGA/HDLBits
Popcount3
장영현
2023. 6. 12. 17:21
728x90
Problem Statement
A "population count" circuit counts the number of '1's in an input vector. Build a population count circuit for a 3-bit input vector.
module top_module(
input [2:0] in,
output [1:0] out );
always @(in)begin
out = 2'b00;
for(integer i = 0; i<3; i++)
begin
if(in[i] == 1'b1)
out = out + 1'b1;
end
end
endmodule