'''
keys: 
Solutions:
Similar:
T:
S:
'''
from typing import List

class Solution:
    
    # O(1) for S and T
    def hammingDistance(self, x: int, y: int) -> int:
        return bin(x ^ y).count('1')
    
    # O(1) for S and T
    def hammingDistance1(self, x: int, y: int) -> int:
        xor = x ^ y
        distance = 0
        while xor:
            # mask out the rest bits
            if xor & 1:
                distance += 1
            xor = xor >> 1
        return distance
    
    def hammingDistance3(self, x: int, y: int) -> int:
        res = 0
        for i in range(32):
            if x & 1 != y & 1:
                res += 1
            x >>= 1
            y >>= 1
        return res
    
    def hammingDistance2(self, x: int, y: int) -> int:
        bx = bin(x)[2:].zfill(32)
        by = bin(y)[2:].zfill(32)
        
        res = 0
        for i in reversed(range(32)):
            if bx[i] != by[i]:
                res += 1
        return res
        