Bit counting
Ian Farquhar
ifarqhar at laurel.ocs.mq.edu.au
Wed Jul 6 19:58:27 PDT 1994
>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++;
> if (a & 4) retval++;
> if (a & 8) retval++;
> if (a & 16) retval++;
> if (a & 32) retval++;
> if (a & 64) retval++;
> if (a & 128) retval++;
>return retval;
>}
[...]
Because on a lot of architectures this implementation may be hideously
inefficient. All the world is not an Intel chip, thank god.
Ian.
More information about the cypherpunks-legacy
mailing list