I've made a little python program that reads binary from a file and stores it to a text file, read the text file and store the binary. But, I can't get the binary to work...
it reads the files like this:
f_bin = open(bin_file,"rb")
to_bin_data = f_bin.read()
bin_data = bin(reduce(lambda x, y: 256*x+y, (ord(c) for c in to_bin_data), 0))
f_bin.close()
Edit: I've now made a long if else script for it, but thanks for the answers
解决方案
Let's take the word 'hello' which is 0110100001100101011011000110110001101111
To translate that back to characters we can use chr and int (with a base of 2) and some list slicing...
''.join(chr(int(bin_text[i:i+8], 2)) for i in xrange(0, len(bin_text), 8))
If we wanted to take 'hello' and convert it to binary we can use ord and string formatting...
''.join('{:08b}'.format(ord(c)) for c in 'hello')