Help with programming with bits
THe problem statement asks "Given that the expression ~0 produces an integer that contains all 1s, write a functioncalled int_size that returns the number of bits contained in an int on your
particular machine."
The solution is:
Code:
int int_size (void)
{
unsigned int bits;
int size = 0;
bits = ~0;
while ( bits ) {
++size;
bits >>= 1;
}
return size;
}
Is the while loop saying while (bits=1)?
If so, I don't understand why bits has to equal one for the size to increase.