My favorite is Kernighan's method for counting set bits. It's as short and clean as the naive method and not immediately obvious: http://graphics.stanford.edu/~seander/bithacks.html#CountBit...
My favorite is Kernighan's method for counting set bits. It's as short and clean as the naive method and not immediately obvious: http://graphics.stanford.edu/~seander/bithacks.html#CountBit...