Just divide by 2 if remainder is '1' increment


#1

int Solution::numSetBits(unsigned int A) {
int count = 1;
if(A == 0) return 0;
while(A!=1 && A!=0){
int z = A%2;
if(z == 1) count++;
A = A/2;
}
return count;

}