```
public int hammingWeight(int n) {
int counter = 0;
while(n!=0) {
if ((n & 1) == 1)
counter++;
n = n >> 1;
}
return counter;
}
```

It seems that the time complexity is O(n) but n is 32 bits integer and best 0 times, worst 32 times. Using for loop always 32 times. Isn't while loop better?