In [4]:
with open('file.bin', 'wb') as f:
f.write("1")
In [5]:
f.close
Out[5]:
In [7]:
with open("file.bin", "rb") as binary_file:
# Read the whole file at once
data = binary_file.read()
print(data)
In [8]:
one_byte = int('11110000', 2)
print(one_byte)
In [11]:
one_byte = int('000110001', 2)
print(one_byte)
In [18]:
a_byte = b'\x31' # 255
In [13]:
i = ord(a_byte) # Get the integer value of the byte
In [14]:
bin = "{0:b}".format(i) # binary 1111111
In [15]:
print (bin)
In [19]:
with open('file.bin', 'wb') as f:
f.write(a_byte)
f.close
# http://www.devdungeon.com/content/working-binary-data-python ; http://www.diveintopython3.net/serializing.html
Out[19]:
In [23]:
with open("file.bin", "rb") as binary_file:
# Read the whole file at once
data = binary_file.read()
print( data)
In [ ]: