You are viewing a single comment's thread. Return to all comments →
python3 simple one liner
def flippingBits(n): return int(''.join(['1' if x == '0' else '0' for x in '%0*d' % (32, int(bin(n)[2:]))]), 2)
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 →
python3 simple one liner
Convert the integer n to a 32-bit binary string, flip each bit, and return the resulting integer.
def flippingBits(n): return int(''.join(['1' if x == '0' else '0' for x in '%0*d' % (32, int(bin(n)[2:]))]), 2)