POP 3CW "09 March 2006" "mathcw-1.00"
Table of contents
pop, lpop, llpop - population count (number of 1-bits)
cc [ flags ] -I/usr/local/include file(s) -L/usr/local/lib -lmcw [ ... ]
#include <mathcw.h>
extern int pop (unsigned int);
extern int lpop (unsigned long int);
extern int llpop (unsigned long long int);
Compute the population count, the number of 1-bits in the
integer argument.
The fast algorithm used allows this to be done in a time that is fixed,
rather than proportional to the number of bits in a word.
Return the population count.
None.
clp2(3CW),
flp2(3CW),
ilog2(3CW),
nlz(3CW),
ntz(3CW).
The book
Henry S. Warren, Jr.
Hacker's Delight
Addison-Wesley (2003)
ISBN 0-201-91465-4
describes several implementations of these functions, and is a general
treasure trove of clever tricks with integer arithmetic.