Last active
October 3, 2023 12:58
-
-
Save 80sVectorz/15c13c043d4a7bb2281bb47107fe7bcc to your computer and use it in GitHub Desktop.
Python script to understand working with bits in byte arrays.
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
import math | |
byte = "|------|" | |
display_length = 10 | |
bit_i=16 | |
byte_i_a = math.floor(bit_i/8) | |
byte_i_b = math.ceil(bit_i/8) | |
print("bit_i:",bit_i) | |
print("byte_i",byte_i_a, byte_i_b) | |
print(" "+" "*max(0,bit_i)+"bit-v") | |
display = list(byte*display_length) | |
display[bit_i] = "+" | |
print(" "*5+"".join(display)) | |
indexes = " "*5 | |
for i in range(display_length): | |
indexes+=f"{i}{' '*7}" | |
print(indexes) | |
print(" "*max(0,byte_i_a)*8+"byte-^") | |
print(" "*max(0,byte_i_b)*8+"byte-^") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment