First I xor the two numbers. Then I count the number of one bits in that number.

```
public class Solution {
public int hammingDistance(int x, int y) {
int z = x ^ y;
int count = 0;
while(z>0){
if(z%2 == 1)
++count;
z /= 2;
}
return count;
}
}
```