/** * :author: Dan Buch (daniel.buch@gmail.com) */ #include int get_bit_count(unsigned int x) { int count=0; while(x) { count++; x = x&(x-1); } return count; } int main() { int to_test[] = {0, 5, 7}; int current; for (int i = 0; i < 3 ; i++) { current = to_test[i]; printf("get_bit_count(%d) = %d\n", current, get_bit_count(current)); } } /* vim:filetype=c:fileencoding=utf-8 */