Encoders
Hub for Computer Whizzes Register to join us

Encoders > More... > C > Program

/* Faster version of bitcount(x). */

#include <stdio.h>

main()
{
        printf("%d\n",bitcount(123));
}

int bitcount(unsigned x)
{
	int b;
        for(b=0;x!=0;x&=x-1)
		b++;
	return b;
}