Counting the 1 bits of a number is needed for Hamming distance, bitmask DP and checking how many flags are set. Brian Kernighan's trick clears the lowest set bit each time, so the loop runs only once per set bit. In real Java code Integer.bitCount does it for you. Interviewers still ask for the manual version to see if you understand x & (x - 1).