Skip to content

Instantly share code, notes, and snippets.

@geekman geekman/bits.py
Created Sep 12, 2019

Embed
What would you like to do?
one-liner combining bits into an integer, the Python way
bits = [1,0,1,0,0,0,0,1]
v = reduce(lambda x, y: x | y,
[n << p for p, n in enumerate(reversed(bits))])
print '%02x' % v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.