Answers for "count 1 bits in a number c++"

C++
1

count bit 1 c++

returns the number of set bits in a integer.
cout<< __builtin_popcount (11); //1011
//Ouput: 3
Posted by: Guest on May-10-2021
3

Count set bits in an integer c++

//Method 1
	int count = __builtin_popcount(number);
//Method 2
	int count = 0;
    while (number) {
        count += number & 1;
        n >>= 1;
    }
Posted by: Guest on May-10-2021

Browse Popular Code Answers by Language