The Hamming distance between two integers is the number of positions at which the corresponding bits are different.

Given two integers x and y, return the Hamming distance between them.

&nbsp;
Example 1:

Input: x = 1, y = 4
Output: 2
Explanation:
1   (0 0 0 1)
4   (0 1 0 0)
       ↑   ↑
The above arrows point to positions where the corresponding bits are different.


Example 2:

Input: x = 3, y = 1
Output: 1


&nbsp;
Constraints:


	0 &lt;=&nbsp;x, y &lt;= 231 - 1


class Solution:
    def hammingDistance(self, x: int, y: int) -> int:
		# First, using XOR Bitwise Operator, we take all distinct set bits.
        z = x ^ y
		# We inicialize our answer with zero.
        ans = 0
		# Iterate while our z is not zero.
        while z:
			# Every iteration we add one to our answer.
            ans += 1
			# Using the expression z & (z - 1), we erase the lowest set bit in z.
            z &= z - 1
        return ans
class Solution {
    public int hammingDistance(int x, int y) {
        int ans=x^y;
        int count=0;
        while(ans>0){
            count+=ans&1;
            ans>>=1;
        }
        
        return count;
    }
}
class Solution {
public:
    int hammingDistance(int x, int y) {
        int val = (x^y);
        int ans = 0;
        for(int i = 31; i >= 0; --i){
            if(val & (1 << i)) ans++;
        }
        return ans;
    }
};
var hammingDistance = function(x, y) {
  x = x.toString(2).split('')
  y = y.toString(2).split('')
  
  let count = 0;
  const len = Math.max(x.length,y.length);

  if (x.length < y.length) {
    x = Array(len - x.length).fill('0').concat(x)
  } else {
    y = Array(len - y.length).fill('0').concat(y)
  } 

  for (let i = 1; i <= len; i++) {
    x.at(-i) !== y.at(-i)? count++ : null    
  }

  return count
};
Hamming Distance