Prev Problem
Next Problem

54. Population Count

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

module popcount8 (
    input  [7:0] in,
    output reg [3:0] count
);
    integer i; // loop variable must be declared (synthesizable)
    always @(*) begin
        count = 4'd0;         
        for (i = 0; i < 8; i = i + 1) begin
        if(in[i]==1)
           count =count+1;
        end
    end
endmodule

 

Was this helpful?
Upvote
Downvote