Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@prschmid
Created January 3, 2013 05:51
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 prschmid/4441128 to your computer and use it in GitHub Desktop.
Save prschmid/4441128 to your computer and use it in GitHub Desktop.
A simple helper function that takes some input data (bytes) and converts it to a string of "bits" for debugging purposes.
def bytes_to_bitstring(bytes, size=32):
"""A simple helper function that takes some input data (bytes) and converts
it to a string of "bits" for debugging purposes.
Args:
bytes: The data to convert to a string of bits
size: The size (in bits) of the input data.
Returns:
A str of length `size` with the bytes converted into a string of bits.
"""
s = ""
for i in range(size):
s = str(bytes & 1) + s
bytes = bytes >> 1
return s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment