Post History
Python (3.6 and up), 32 bytes (unsigned integer I/O) lambda x:int(f'{x:08b}'[::-1],2) Input and output are int objects. This also reverses the bits in integers larger than 255, implicitly infer...
Answer
#1: Initial revision
# Python (3.6 and up), 32 bytes (unsigned integer I/O) ``` lambda x:int(f'{x:08b}'[::-1],2) ``` Input and output are `int` objects. This also reverses the bits in integers larger than 255, implicitly inferring their bit length from the number of bits needed to write them (even if that isn't a multiple of 8). It will raise an exception if given a negative number as input. ## Python (3.6 and up), 44 bytes (byte I/O) ``` lambda x:bytes([int(f'{x[0]:08b}'[::-1],2)]) ``` Input and output are both actual `bytes` objects. This uses new-style string formatting to produce the bit-pattern directly (and takes advantage of the fact that indexing a `bytes` in 3.x gives an integer value), and uses the `bytes` constructor to produce a valid `bytes` object as the result (In Python 3.x, `chr` produces a string, not `bytes`).