Created
January 3, 2013 05:51
-
-
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.
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
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