Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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
???
 

grieblm

Member level 4
Joined
May 7, 2011
Messages
75
Helped
18
Reputation
36
Reaction score
18
Trophy points
1,308
Location
Georgetown, Canada
Activity points
1,734
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

Top