def hamming(a, b, bitdepth): distance = 0 for i in range(bitdepth - 1, -1, -1): bit_a = (a >> i) & 1 bit_b = (b >> i) & 1 distance += not(bit_a == bit_b) return distance