Skip to content

Instantly share code, notes, and snippets.

@maazrk
Created July 9, 2017 16:39
Show Gist options
  • Save maazrk/f6270e23fc099cc8405cac78b0c3122d to your computer and use it in GitHub Desktop.
Save maazrk/f6270e23fc099cc8405cac78b0c3122d to your computer and use it in GitHub Desktop.
Write a function to determine the number of bits required to convert integer A to integer B.
def bitswaprequired(a, b):
count = 0
c = a^b
while(c != 0):
count += c & 1
c = c >> 1
return count
print(bitswaprequired(12, 7))
#OUTPUT = 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment