Created
July 9, 2017 16:39
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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