#include <stdio.h>

#define N	8

static int bit0_is_on(unsigned int i)
{
	return i & 1; // == i % 2
}


// equivalent to __builtin_popcount()
static int popcount(unsigned int i)
{
	int count = 0;

	while (i != 0) {
		count += bit0_is_on(i);
		i = i >> 1;
	}

	return count;
}

int main()
{
	for (unsigned int i = 0; i < (1 << N); i++) {
		printf("%08b -> popcount = %d\n", i, popcount(i));
	}
	return 0;
}

