#/usr/bin/python3
# ====================================================================
# convert a byte to bits
# ====================================================================
# --------------------------------------------------------------------
# ---- convert a byte to bits
# ---- return a list of 1s and 0s as integers
# --------------------------------------------------------------------
def byte1(byt):
bit_list = [int(i) for i in f"{byt:08b}"]
return bit_list
# --------------------------------------------------------------------
# ---- convert a byte to bits
# ---- return a string of 1s and 0s as characters
# ----
# ---- FYI: b = bin(byt)
# ---- print(f'bin(byt) = {type(b)} ({b})')
# --------------------------------------------------------------------
def byte2(byt):
bit_str = bin(byt)[2:].rjust(8,'0')
return bit_str
# --------------------------------------------------------------------
# ---- main
# --------------------------------------------------------------------
# ---- 'A' = 0X41 (0100 0001)
print(f"ord('A') = {ord('A'):x} hex")
byt = ord('A')
print()
x = byte1(byt)
print(f'type={type(x)} {x}')
print()
x = byte2(byt)
print(f'type={type(x)} {x}')