Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

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;
    }
 
PREVIOUS NEXT
Tagged: #Count #set #bits #integer
ADD COMMENT
Topic
Name
8+3 =