I have got this question: Write function of f(x) that return the number of bits set to 1 in an unsigned integer.
So the outcome of the result will be sometime like f(5) = 2 cos [5 in binary is 101 and it got 2 '1s')
Here's my program:
#include <stdio.h>
int bitcount(unsigned x);
main()
{
int b;
int x;
for (b=0; x!=0; x >>=1)
if (x &01)
b++
return b;
}
And the error is "return b" >> parse error before `return'
how should i ammend this? Please advise. Thanks.