def hamming(a, b):
"""Compute the hamming distance between 2 int.
:param a: a 64 bits integer
:param b: a 64 bits integer
:type a: int
:type b: int
:return: the hamming distance between a, b
:rtype: int
"""
a = bin(a)[2:][::-1]
b = bin(b)[2:][::-1]
it = itertools.zip_longest(a, b, fillvalue='0')
return sum([va != vb for (va, vb) in it])
评论列表
文章目录