Forum Discussion
Altera_Forum
Honored Contributor
15 years agoCounting the position of ones in a binary vector
I want to design a combinatorial circuit for an fpga which will count the position of ones in a 16 bit vector. eg1 if vector is 16'b0000_0000_0011_0101 then output should be 64'h0000_0000_0000_5...
Altera_Forum
Honored Contributor
15 years ago --- Quote Start --- Actually it can be done in a combinatorial way but you dont take a case statement approach... i think there is a way... --- Quote End --- Case statements would only inflate the code. josyb has shown an exact solution of your original problem, taking advantage of the VHDL iteration constructs. If you want a pure combinational solution for some reason, you can simply remove the if rising_edge(clk) condition. The assignment to the slice lq(j*4+3 downto j*4) isn't accepted at least by my VHDL version, I think a slice must generally needs a constant range. I used a bitwise copy instead. --- Quote Start --- i dont know how to remove those extra zeros. --- Quote End --- The suggested solution gives the results specified in your original post.