I have a sequence of bits for example 0101, and I want to save this sequence to a file in binary format and while opening the saved file using a binary viewer, I need to show me exactly 0101 [I mean 4 bits]. but it showed me 00000000 00000001 00000000 00000001 [and this is 32 bits].
May I ask you to help me guys? Thanks
My Code:
f = open('my_file', 'w+b')
byte_arr = [0, 1, 0, 1]
binary_format = bytearray(byte_arr)
print(binary_format)
f.write(binary_format)
f.close()
The Screenshot:

BitWriterclass).