13,696 questions

18,622 answers

573 users

#include <stdio.h> unsigned int count_set_bits(unsigned int n) { unsigned int count = 0; while (n) { count += n & 1; n >>= 1; } return count; } int main() { int n = 45; // 00101101 printf("%i", count_set_bits(n)); return 0; } /* run: 4 */