Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top