''.join(format(ord(i), 'b') for i in string)
This line of code gives the binary representation of string data, now for me to edit the binary version I have to convert the binary data representation to string again. Like this:
string = 'hello'
bin_string = ''.join(format(ord(i), 'b') for i in string)
print (bin_string)
# Output: 11010001100101110110011011001101111
bin_string = str(bin_string)
#even if I don't convert it to string it will end up a string because I edited it
Now let's say bin_string ended up as '11010001100101101010101001101111' after my edits, is there a way of getting it back to a binary datatype and not save the 0s and 1s as a string?
bin_string = str(bin_string)does nothing, becausebin_stringwas already an instance ofstr.'11010001100101101010101001101111'is a string of consistent (n) size bit lengths.