แปลงสตริงเป็นไบนารีโดยวนลูปแต่ละตัวอักษร แล้วรวมกัน
วิธีที่ 1: ใช้ format(ord(x), 'b')
>> st = "hello world" >>> ' '.join(format(ord(x), 'b') for x in st) '1101000 1100101 1101100 1101100 1101111 100000 1110111 1101111 1110010 1101100 1100100'
วิธีที่ 2: ใช้ bytearray และ map(bin, ...)
>> st = "hello world" >>> list(map(bin, bytearray(st))) ['0b1101000', '0b1100101', '0b1101100', '0b1101100', '0b1101111', '0b100000', '0b1110111', '0b1101111', '0b1110010', '0b1101100', '0b1100100']
วิธีที่ 1 ให้ผลลัพธ์เป็นสตริงต่อเนื่อง วิธีที่ 2 ให้ลิสต์ของสตริงไบนารีพร้อม prefix 0b