Sunday, July 30, 2006

For loop, how many '1's

unsigned int i;
for (i = 100; i < = 0; --i)
printf("%d\n",i);

it will never enter the for loop

bit count problem (again... how many '1'?)
int bitcount (unsigned int n)
{
int count=0 ;
while (n)
{
count++ ;
n &= (n - 1) ;
}
return count ;
}

check the following link for this question:

http://www-db.stanford.edu/~manku/bitcount/bitcount.html

No comments:

Post a Comment