Skip to content

Home

Hamming distance

Calculates the Hamming distance between two values.

def hamming_distance(a, b):
  return bin(a ^ b).count('1')

hamming_distance(2, 3) # 1

More like this

Start typing a keyphrase to see matching snippets.