This function was posted in the comp.lang.vhdl group:
Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
function count_ones(slv :std_logic_vector)returnnaturalisvariable n_ones :natural:=0;beginfor i in slv'rangeloopif slv(i)= '1' then
n_ones := n_ones +1;endif;endloop;return n_ones;endfunction count_ones;