function to get number of set bits in an integer c++ code example
Example: Count set bits in an integer c++
//Method 1
int count = __builtin_popcount(num);
//Method 2
int count = 0;
while (num) {
count += num & 1;
n >>= 1;
}