Last active
August 29, 2015 14:13
-
-
Save ariscop/aec6f13de1c00b7ce14f to your computer and use it in GitHub Desktop.
This file contains 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
def _bits(byte): | |
return [(byte >> 0) & 1, | |
(byte >> 1) & 1, | |
(byte >> 2) & 1, | |
(byte >> 3) & 1, | |
(byte >> 4) & 1, | |
(byte >> 5) & 1, | |
(byte >> 6) & 1, | |
(byte >> 7) & 1] | |
def iter_bits(input): | |
for byte in input: | |
yield from _bits(byte) | |
def bits(byte): | |
return [bit for bit in iter_bits(byte)] | |
for x in iter_bits(b'foo'): print(x) | |
print(bits(b'bar')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment