1//Method 1
2 int count = __builtin_popcount(number);
3//Method 2
4 int count = 0;
5 while (number) {
6 count += number & 1;
7 n >>= 1;
8 }
1//Method 1
2 int count = 0;
3 while (n)
4 {
5 count++;
6 n >>= 1;
7 }
8//Method 2
9 int count = (int)log2(number)+1;