The program main call a func that just counts the binary 1 in an 8 bit number. Please see line in RED below.
I do not know how result is incremented based on the highlighted line. I looked through my C programming book and could not find anything that describes the statement. It does work however.
Code:
int i=1, myInt;
int main(int argc, char *argv[]) {
i=37; //"00100101" in binary, contains three bits that are set to "1".
myInt=count_ones(i);
printf("%d\r\n",myInt);
}
//A simple example of C code, designed to count the 1 bits in a int, might look like this:
int count_ones(unsigned int x) {
int result = 0;
while (x != 0)
result++, x = x & (x-1);
return result;
}