PREP44 Editorial

Problem Explanation

we are given an unsigned 32 bit integer and we have to output the number of set bits in the this integer

Approach

We initialize a variable from 0 and start a loop till the number is not 0. Then if the bit at the one^{th} position is set we add it to the count (We can check this by n&1, this will be 1 if the bit at one^{th} position is 1 otherwise it will be 0) and shift the bits of the number to the right by one.