I found an interesting algorithm to calculate hamming distance on this site:
def hamming2(x,y):
"""Calculate the Hamming distance between two bit strings"""
assert len(x) == len(y)
count,z = 0,x^y
while z:
count += 1
z &= z-1 # magic!
return count
The point is that this algorithm only works on bit strings and I'm trying to compare two strings that are binary but they are in string format, like
'100010'
'101000'
How can I make them work with this algorithm?
bin(int('100010',2))
produces binary. – Wristband