Let's take a bad number, ie, not a power of 2. Let's take 53.
In binary, 53 = 110101. (4 ones, 2 zeroes)
c <<= 3;
will give us the number of bits required to represent 53 in binary. See Digvijay Pandey's answer.
Now,
while(x = x & x-1) c--;
When x is bitwise-ANDED with (x-1), it is a property that this result would contain one less 1 than x.
53 AND 52 = 110101 AND 110100 = 110100 (4 1's reduced to 3 1's)
110100 is 52. So,
52 AND 51 = 110100 AND 110011 = 110000 (3 1's reduced to 2 1's)
110000 is 48, So
48 AND 47 = 110000 AND 101111 = 100000 (2 1's reduced to 1 1)
100000 is 32, So
32 AND 31 = 100000 AND 011111 = 0 (1 1 reduced to 0 1's)
It took 4 steps. At each step we decremented c.
=> We decremented c four times.
=> From the bits required to represent 53, we subtracted 4 bits.
=> Number of bits remaining is the count of 0's in 53.
Option C