Two approaches:
Check each bit: AND with 1, count if set, shift right. Repeat 32 times.
Brian Kernighan's trick: n & (n - 1) clears the rightmost set bit. Count how many times you can do this before n becomes 0.
The second approach runs in where is the number of set bits, often faster than checking all 32 bits.