You are viewing a single comment's thread. Return to all comments →
Python 3 solution Easy to understand although not very efficient
def flippingBits(n): b = bin(n)[2:].zfill(32) # n as 32 bits b_inv ='' for digit in b: if digit == '1': b_inv += '0' else: b_inv += '1' return int(b_inv,2) # decimal to binary
Seems like cookies are disabled on this browser, please enable them to open this website
Flipping bits
You are viewing a single comment's thread. Return to all comments →
Python 3 solution Easy to understand although not very efficient