I think you could make it cleaner like this:
>>>''.join(format(ord(c), '08b') for c in 'This is my string') '0101010001101000011010010111001100100000011010010111001100100000011011010111100100100000011100110111010001110010011010010110111001100111'
the format function will represent the character in an 8-digit binary representation.
Cezar Spatariu Neagu Sep 26 '13 at 9:21 2013-09-26 09:21
source share