Skip to content

Instantly share code, notes, and snippets.

@crowjdh
Created January 6, 2022 07:17
Show Gist options
  • Save crowjdh/ea9106ae239e86faac5eded3d44e695a to your computer and use it in GitHub Desktop.
Save crowjdh/ea9106ae239e86faac5eded3d44e695a to your computer and use it in GitHub Desktop.
def bytes_to_bits(bytes):
bits_repr = bin(int(bytes, base=16))[2:]
bits = []
for end_idx in range(len(bits_repr) - 1, 0 - 1, -4):
end_idx = end_idx + 1
start_idx = max(0, end_idx - 4)
bits_chunk = bits_repr[start_idx:end_idx]
bits.append(bits_chunk)
return list(reversed(bits))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment