[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bit counting



>From: Ian Farquhar <[email protected]>
>Date: Thu, 7 Jul 1994 12:57:54 +1000 (EST)
>
>>Why bother when you can simply do an eight line function?
                                       ~~~~~
>>int bitcount(char b)
>>{
>>register int retval=0;
>
>> if (a & 1) retval++;
>> if (a & 2) retval++;
        etc.
>>return retval;
>>}
>
>Because on a lot of architectures this implementation may be hideously
>inefficient.  All the world is not an Intel chip, thank god.

Not to mention it's only good for 8-bit words.  In my case I am working
with 16-bit data.

tw