Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ariscop
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ariscop/aec6f13de1c00b7ce14f to your computer and use it in GitHub Desktop.
Save ariscop/aec6f13de1c00b7ce14f to your computer and use it in GitHub Desktop.
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