I thought the input should be valid int, but actually it's not. Is there any problem with this algorithm?

```
public int hammingWeight(int n) {
if(n==1||n==0)
return n;
int temp=n;
int count=0;
int res=1;
while(res!=0){
res=temp/2;
int mod=temp%2;
if(mod==1)
count++;
temp=res;
}
return count;
}
```