Bit counting

tim werner werner at mc.ab.com
Thu Jul 7 04:53:19 PDT 1994


>From: Ian Farquhar <ifarqhar at laurel.ocs.mq.edu.au>
>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






More information about the cypherpunks-legacy mailing list