Skip to content

Instantly share code, notes, and snippets.

@dketov
Last active October 24, 2017 19:58
Show Gist options
  • Save dketov/6b80cf49d7ff0988f508da71f113a9f8 to your computer and use it in GitHub Desktop.
Save dketov/6b80cf49d7ff0988f508da71f113a9f8 to your computer and use it in GitHub Desktop.
a = 0xdeadbeef
print bin(a)
def gbits(a):
while a:
yield a & 0x1
a >>= 1
print tuple(bit for bit in gbits(0xdeadbeef))
_, bits = reduce(
lambda (a, bits), bitnum: (a >> 1, bits + (a & 0x1,)),
xrange(a.bit_length()),
(a, ())
)
print bits
print tuple(
(a >> bit) & 0x1
for bit in xrange(a.bit_length())
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment