Bitcounter Function Help

Im looking for a single expression that counts the number of bits in an integer to replace the 0 of the return in the function
I cant use any loops, so im very confused. can only use 1 expression. I can make use of any operators, recursion, and bit shifts. I also cant change main. Any help would be appreciated


uint32_t bitcounter(uint32_t x)
{
return 0;
}

int main()
{
uint32_t n, bits;

n=33
bits = bitCounter(n);
return 0;
}
return x == 0 ? 0 : ((x & 1) + bitcounter(x >> 1));
Thank you so much liuyang. that was very helpful
Topic archived. No new replies allowed.