Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
xor + bit count solution in Clear category for The Hamming Distance by Lasica
def checkio(n, m):
# n ^ m == n xor m, it xors bits: 1^1==0, 1^0==1, 0^1==1, 0^0==0
v = n^m # count the number of bits set in v which is xor of numbers
c = 0 # c is counter of the total bits set in v
while v:
v &= v - 1; # clear the least significant bit set
c += 1
return c
April 22, 2014