class Solution {
public:
int NumberOf1(int n) {
int res = 0;
while(n) {
int x = n & (-n);
if(x) {
res++;
n = n - x;
}
}
return res;
}
};