Dal K&R ho trovato questa:
/* bitcount: count 1 bits in x */
int bitcount(unsigned x)
{
int b;
for (b = 0; x != 0; x >>= 1)
if (x & 01)
b++;
return b;
}
che ritorna il numero di bits uguali ad 1, io ho solo tolto l'IF per fargli contare anche quelli a 0,
ho provato e sembra funzionare...

