Filp Bits
Source
- lintcode: Flip Bits
Determine the number of bits required to flip if you want to convert integer n to integer m.
Example
Given n = 31 (11111), m = 14 (01110), return 2.
Note
Both n and m are 32-bit integers.
Python
class Solution:
"""
@param a, b: Two integer
return: An integer
"""
def bitSwapRequired(self, a, b):
# write your code here
count=0
xor = a^b
for i in range(32):
count += (xor&1)
xor>>=1
return count