int('{:08b}'.format(n)[::-1], 2)
You can specify any filling length in place of the 8. If you want to get really fancy,
b = '{:0{width}b}'.format(n, width=width)
int(b[::-1], 2)
lets you specify the width programmatically.
More Related Contents:
- a pythonic way of doubling consecutive binary bits [closed]
- Bitwise operation and usage
- ‘and’ (boolean) vs ‘&’ (bitwise) – Why difference in behavior with lists vs numpy arrays?
- Generate random integers between 0 and 9
- Converting integer to string in Python
- How do you round UP a number?
- The `is` operator behaves unexpectedly with non-cached integers
- Converting integer to binary in python
- Convert floats to ints in Pandas?
- How can I check if a string represents an int, without using try/except?
- bit-wise operation unary ~ (invert)
- Why (0-6) is -6 = False? [duplicate]
- RGB Int to RGB – Python
- Convert integer to string in Python
- Safest way to convert float to integer in python?
- converting a list of integers into range in python
- How do you express binary literals in Python?
- How to convert a string of space- and comma- separated numbers into a list of int? [duplicate]
- Splitting List That Contains Strings and Integers
- How do I check if raw input is integer in python 2.7?
- Is & faster than % when checking for odd numbers?
- Is there a built-in or more Pythonic way to try to parse a string to an integer
- Convert all strings in a list to integers
- Reading integers from binary file in Python
- Round a floating-point number down to the nearest integer?
- Two’s Complement Binary in Python?
- How can I convert string values from a dictionary, into int/float datatypes?
- Convert a number to a list of integers [duplicate]
- Python: Set Bits Count (popcount) [duplicate]
- How do I add together integers in a list (sum a list of numbers) in python?