I would like to do a simple operations, but I'm not able to manage it. I have a string of '0' and '1' derived by a coding algorithm. I would like to write it to file but I think that I'm doing wrongly.
My string is something like '11101010000......10000101010'
Actually I'm writing a binary file as:
print 'WRITE TO FILE '
with open('file.bin', 'wb') as f:
f.write(my_coded_string)
print 'READ FROM FILE'
with open('file.bin', 'rb') as f:
myArr = bytearray(f.read())
myArr = str(myArr)
If I look at the size of the file, I get something pretty big. So I guess that I'm using an entire byte to write each 1 and 0. Is that correct?
I have found some example which use the 'struct' function but I didn't manage to understand how it works.
Thanks!