Set bits in log(n)

 int set_bits(int n){

    int  count=0;

    while(n){

        n=n&(n-1);

        count++;

    }

    return count;

}

Comments

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings