What does this function do?

c, c++

Solution

It counts number of 1's in binary representation of n

Problem

I am reading a program which contains the following function, which is ``` int f(int n) { int c; for (c=0;n!=0;++c) n=n&(n-1); return c; } ``` I don't quite understand what does this function intend to do?

Original source