count of bits set in a long

Karl Heuer karl at haddock.ima.isc.com
Wed Oct 3 13:43:55 AEST 1990


In article <12330 at crdgw1.crd.ge.com> davidsen at crdos1.crd.ge.com (bill davidsen) writes:
>[Aren't these solutions non-portable?]

Didn't the original problem ask for the bit count of "a 32-bit word"?  In
any case, most of the solutions can be easily configured to use the constants
from <limits.h>.  (I may have left them out of my solution, for brevity.)

The two's complement assumption isn't a problem if you define the argument to
be an unsigned type (which it *should* be, if you're doing bit manipulations).

Karl W. Z. Heuer (karl at kelp.ima.isc.com or ima!kelp!karl), The Walking Lint



More information about the Comp.lang.c mailing list