# 461. Hamming Distance

`Input: x = 1, y = 4Output: 2Explanation:1   (0 0 0 1)4   (0 1 0 0)       ↑   ↑The above arrows point to positions where the corresponding bits are different.`
`Input: x = 3, y = 1Output: 1`
• `0 <= x, y <= 231 - 1`
`class Solution:    def hammingDistance(self, x: int, y: int) -> int:        total=0        while(x or y):            total+=(x&1) ^ (y&1)            x>>=1            y>>=1        return(total)`
`class Solution:    def hammingDistance(self, x: int, y: int) -> int:        total=0        xor_=x^y        while(xor_):            xor_=(xor_) & (xor_-1)            total+=1        return(total)`

--

--

--

## More from Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

## Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.