Most efficient way to calculate hamming distance in ruby?
问题 In ruby, what is the most efficient way to calculate the bit difference between two unsigned integers (e.g. the hamming distance)? Eg, I have integer a = 2323409845 and b = 1782647144. Their binary representations are: a = 10001010011111000110101110110101 b = 01101010010000010000100101101000 The bit difference between the a & b is 17.. I can do a logical XOR on them, but that will give me a different integer != 17, I would then have to iterate through the binary representation of the result