Number of 1 Bits (Brian Kernighan)

Easy · Bit Manipulation · about 10 minutes

Asked at Apple, Microsoft, Bloomberg.

Given a non-negative integer n (below 2³¹), return the number of set bits in its binary representation (its Hamming weight).