What we've got here is a loop that counts the number of "1" bits in a given number b. After this loop runs, b will equal zero and n will equal the number of 1 bits in b. The tricky part of that loop is the bitwise AND operator, the &=. Given two numbers, a bitwise AND will examine each bit in each number and set the corresponding bit in a result to 1 if both bits in the given numbers were 1; or in any other case . If you're not already familiar with this, you really ought to read Wharfinger's writeup for bitwise.

So how does it work? Let us unroll that loop! Set b equal to 45 (0010 1101) and let 'er rip.

What's going on here? When you subtract 1 from a binary number, you're really turning off the rightmost 1 and turning on every bit after it. Toggling them all, if you will. Let's explicate the loop again. This time, pay close attention to what happens when we logically AND the two numbers together.

Each iteration through the loop, everything from the least significant 1 bit to the least significant bit is ANDed with its inverse, setting them and every bit betwixt the two to zero. Since the loop eats precisely one bit at a time, it will run until all of the bits have been turned to zeros, leaving n equal to the number of times the loop was processed, and thus counting the 1 bits in that given number b.