Skip to content

Instantly share code, notes, and snippets.

@mizhi
Last active November 25, 2021 00:48
Show Gist options
  • Select an option

  • Save mizhi/acecabd05e34420d8404f4d99118bc1a to your computer and use it in GitHub Desktop.

Select an option

Save mizhi/acecabd05e34420d8404f4d99118bc1a to your computer and use it in GitHub Desktop.
# From a daily programming challenge on the Operation Code slack
def hamming(x: int, y: int) -> int:
"""Compute number of bits where x and y differ.
"""
z = x ^ y
count = 0
while z > 0:
count += (z & 0x1)
z >>= 1
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment