181 - Flip Bits
Written on October 21, 2015
Tweet
Determine the number of bits required to flip if you want to convert integer n to integer m.
class Solution:
"""
@param: a: An integer
@param: b: An integer
@return: An integer
"""
def bitSwapRequired(self, a, b):
# write your code here
xor = a ^ b
count = 0
for i in xrange(32):
if xor & 1 == 1:
count += 1
xor >>= 1
return count