I was trying to count the number of consecutive bits of a bit-stream and I have this code. I assume that, this has to to run until when the number becomes 0 and the count then should return the value. But why is there no conditional statement to equate the number to zero(otherwise i doubt this can be an infinite loop) so that the execution jumps out of the loop and returns the count value once it's over. Please don't duplicate it as I'm only a kid without adequate reputation to comment any doubt.
int count_consecutive_ones(int in) {
int count = 0;
while (in)
{
in = (in & (in << 1));
count++;
}
return count;
}