Last active
October 24, 2017 19:58
-
-
Save dketov/6b80cf49d7ff0988f508da71f113a9f8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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