Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

VHDL Order 0s and 1s

Status
Not open for further replies.

SGTheDreamer

New Member
Hey guys! :D I need to do something on VHDL.

The problems is this: I have a 8 bit input, and i have to order the bits of it.
The zeros to the right and the Ones to the left.
Example :
input <= "01100011"
output<= "11110000"
I need to count the number of zeros or ones but without foor loop.
With foor loop its something like this:
for i in 0 to 7 loop
if input(i) = '1' then
count <= count + 1;
end loop;
but i have to do it WITHOUT that sentence.
If you guys could give me ideas, I ll be so happy. :D
Nice day.
 
Here is a 32 bit implementation from StackExchange

C:
int CountOnesFromInteger(uint32_t i)
{
    i = i -((i >>1) & 0x55555555);
    i =(i & 0x33333333)+((i >>2) & 0x33333333);
    return(((i +(i >>4))& 0x0F0F0F0F)* 0x01010101)>>24;
}

It would be easy to run as 8 bit!!
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top