Brian Kernighan’s Algorithm to count set bits in an integer | Techie Delight
The Brian Kernighan’s algorithm is used to count its set bits of an integer. It only consider the set bits of an integer by turning off its rightmost set bit (after counting it), so the next iteration of the loop considers the next rightmost bit.
Techie Delight