Answers for "converting text to binary python"

1

binary to text python

a_binary_string = "01100001 01100010 01100011"
ascii_string = "".join([chr(int(binary, 2)) for binary in a_binary_string.split(" ")])
# ascii_string = "abc"
Posted by: Guest on April-20-2021
3

char to binary python

>>> st = "hello world"
>>> ' '.join(format(ord(x), 'b') for x in st)
'1101000 1100101 1101100 1101100 1101111 100000 1110111 1101111 1110010 1101100 1100100'

#using `bytearray`
>>> ' '.join(format(x, 'b') for x in bytearray(st, 'utf-8'))
'1101000 1100101 1101100 1101100 1101111 100000 1110111 1101111 1110010 1101100 1100100'
Posted by: Guest on May-30-2020

Code answers related to "converting text to binary python"

Python Answers by Framework

Browse Popular Code Answers by Language