Answers for "Count set bits in an integer c++"

C++
2

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
2

bit counting

countBits = (n) => n.toString(2).split("0").join("").length;
Posted by: Guest on June-19-2020
0

count bits c++

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

Code answers related to "Count set bits in an integer c++"

Browse Popular Code Answers by Language