You're viewing a comment by Kumar and its responses.

Kumar Permalink
July 02, 2009, 10:30

Count the number of bits set -

int count_set_bits( int n )
{
int count = 0;
while ( n ) {
++count;
n &= (n-1);
}
return count;
}

The loop runs only as many times as there are bits set in n.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "halflife3_143": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.