Answers for "convert binary file to string python"

2

text to binary python

a_string = "abc"

a_byte_array = bytearray(a_string, "utf8")

byte_list = []

for byte in a_byte_array:

    binary_representation = bin(byte)
    byte_list.append(binary_representation)

print(byte_list)

#Output ['0b1100001', '0b1100010', '0b1100011']
Posted by: Guest on October-28-2021
2

format binary string python

x = 10
print(format(x, '#b')) # 0b1010
print(format(x, 'b')) # 1010
x= 0xF
print(format(x, 'b')) # 1111
print(f'{x:b}') # 1111 (If you knew this format, you are Python Ninja!)
Posted by: Guest on July-20-2020

Code answers related to "convert binary file to string python"

Python Answers by Framework

Browse Popular Code Answers by Language