Brian Kernighan's algorithm
RU: алгоритм Брайана Кернигана
A method for counting set bits: n &= n - 1 clears the lowest set bit, so looping until n reaches zero takes one iteration per set bit. Its cost is O(number of set bits), not O(word size).
RU: алгоритм Брайана Кернигана
A method for counting set bits: n &= n - 1 clears the lowest set bit, so looping until n reaches zero takes one iteration per set bit. Its cost is O(number of set bits), not O(word size).