In a nutshell
Numbers are stored as binary — a row of 0s and 1s. Counting how many 1s a number has uses a neat trick: n & (n−1) erases the lowest 1 and leaves every other bit alone. Each time you apply it you've removed exactly one 1, so repeating until the number hits zero counts the 1s in as many steps as there are 1s, rather than scanning all the bits.