SHARE
TWEET

Untitled

a guest Feb 21st, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def reverse_bits(n):
  2.     assert 1 <= n <= 1000000000,\
  3.         'argument must be in range [1, 1000000000]'
  4.     r = 0
  5.     while n:
  6.         r <<= 1
  7.         r |= n & 1
  8.         n >>= 1
  9.     return r
  10.  
  11.  
  12. if __name__ == '__main__':
  13.     import sys
  14.     if len(sys.argv) > 1 and sys.argv[1].isdigit():
  15.         print(reverse_bits(int(sys.argv[1])))
  16.     else:
  17.         print('Usage: {} <N>'.format(sys.argv[0]))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top