There is a two-character spell that clears the lowest set bit of any integer: n & (n−1). Subtracting one flips the lowest 1 to 0 and all the zeros below it to 1; ANDing with the original wipes that whole tail. Repeat until you hit zero, counting the steps, and you have the population count — but the loop runs only once per set bit, not once per bit. For sparse words that is a large win, and the identity itself is a small marvel of two’s-complement.
The demo counts the 1-bits of 23 (10111) by clearing the lowest set bit each step, showing the word shrink to zero in four steps: live demo
“Counting bits means looking at every bit.” — only at the set ones: n & (n−1) skips straight to the next 1. cited
The lowest 1 struck off with a single AND — a bit-count that visits only what is set. resource
On the canonical compiler, clearing the lowest set bit of 23 four times reaches zero — 23 has four 1-bits: