Mail Archives: djgpp/1999/08/13/14:53:47
what would I do, is the following:
I would create a byte with the value of 1(binary 00000001)
and take your byte and do a bitwise "and"
char a=1;
char b=YOUR_NUMBER;
int i=0;
int z;
for(z=0;z<8;z++)
{
if((a | b) = 1)
i++;
a << 1; //I haven't programmed in C for 4 years now, so I guess that's
how is the bit shift, but I am not sure
}
you check the bit, you shift, check shift, etc.
but I am not sure if the code is correct, or algorithm is the fastest,
but hope this helps.
Anders David Skarin wrote:
> Hi,
>
> What is the fastest way (or just a damn fast way) to
> count the nr of binary 1's in a byte/word/dword ?
>
> Is there any assembler instruction for this ?
> (there should be, considering the nr of instructions
> in the sisc processors)
>
> Thanks!
>
> David Skarin
- Raw text -