Alex Rivera | Logout

What does this function do?

Asked 2010-07-16T14:35:44.227
23

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?

c++ c
Edit
Report

1 Answer

0

Could it be it tries to return the number of significant bits in n? (Haven't thought through it completely...)

answered 2010-07-16T14:39:52.323

Your Answer