vhdl code to count the total number of bits

Status
Not open for further replies.

chitra ranganath

Member level 2
Joined
May 15, 2011
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,568
hi how to count the total no of bits stored in a register which includes even a space in between
???
 

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) return natural is 
  variable n_ones : natural := 0; 
begin 
  for i in slv'range loop 
    if slv(i) = '1' then 
      n_ones := n_ones + 1; 
    end if; 
  end loop; 
  return n_ones; 
end function count_ones;

 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…