Cleaner version:

>>> test_string = '1101100110000110110110011000001011011000101001111101100010101000'
>>> print ('%x' % int(test_string, 2)).decode('hex').decode('utf-8')
نقاب

Inverse (from @Robᵩ's comment):

>>> '{:b}'.format(int(u'نقاب'.encode('utf-8').encode('hex'), 16))
1: '1101100110000110110110011000001011011000101001111101100010101000'
Answer from Igonato on Stack Overflow
🌐
AskPython
askpython.com › python › examples › binary-to-utf8-conversion
How to Convert Binary Data to UTF-8 in Python - AskPython
April 10, 2025 - Another technique that works for unknown binary data is to base64 encode it first. Base64 produces UTF-8 compatible text output from any binary input. import base64 data = b"\x12\xab" # Base64 encode b64_data = base64.b64encode(data) # Now decode base64 text from UTF-8 to string text = b64_data.decode("utf-8") print(text) # Output: Eqs=
Discussions

python - binary -> UTF-8 -> string - Stack Overflow
I'm trying to understand Unicode and all asociated things. I have made an utf-8.txt file which obviously is encoded in utf-8. It has "Hello world!" inside. Heres what I do: f = open('utf8.txt', mo... More on stackoverflow.com
🌐 stackoverflow.com
July 14, 2016
Binary to String/Text in Python - Stack Overflow
I have searched many times online and I have not been able to find a way to convert my binary string variable, X X = "1000100100010110001101000001101010110011001010100" into a UTF-8 string value. I More on stackoverflow.com
🌐 stackoverflow.com
utf 8 - python - convert binary data to utf-8 - Stack Overflow
import base64 encoded = base64.b64encode(image_binary_data) ... Encoding means converting strings to storable bytes. And Decoding means converting bytes to readable strings. The data in your code is already encoded. ... Image cannot be converted into something like charters in utf8. ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... 1 How to convert a string representation of 'bytes' to its corresponding 'utf-8' in Python... More on stackoverflow.com
🌐 stackoverflow.com
python - How to convert 'binary string' to normal string in Python3? - Stack Overflow
@HanfeiSun what you call a "binary string" is a bytes object (see information about bytes object in the standard library ) ... Save this answer. ... Show activity on this post. ... To get bytes from string, encode it. ... Sign up to request clarification or add additional context in comments. ... @lyomi, I used ascii because the given string was made with ascii letters. You don't need to specify encoding if the encoding is utf-8 (default in Python ... More on stackoverflow.com
🌐 stackoverflow.com
March 30, 2016
🌐
freeCodeCamp
freecodecamp.org › news › python-bytes-to-string-how-to-convert-a-bytestring
Python Bytes to String – How to Convert a Bytestring
April 10, 2023 - We specify the encoding format as utf-8 using the encoding parameter. Finally, we print the resulting string to the console. We can also use the bytes() constructor, a built-in Python function used to create a new bytes object.
🌐
GitHub
github.com › glmcdona › binary2strings
GitHub - glmcdona/binary2strings: Python module to extract Ascii, Utf8, and Unicode strings from binary data. Lightning fast wrapper around c++ compiled code. · GitHub
Returns an array of tuples ordered according to the order in which they are located in the binary: string: The resulting string that was extracted in standard python string. All strings are converted to Utf8 here.
Author: glmcdona
🌐
Learning Python
learning-python.com › strings30.html
Python 3.X Strings Tutorial by Mark Lutz
C:\misc>c:\python30\python.exe >>> F = open('data.bin', 'wb') # open binary output file >>> import struct >>> data = struct.pack('>i4sh', 7, b'spam', 8) # create packed binary data >>> data # bytes in 3.0, not str b'\x00\x00\x00\x07spam\x00\x08' >>> F.write(data) # write to the file 10 >>> F.close() >>> F = open('data.bin', 'rb') # open binary input file >>> data = F.read() # read bytes >>> data b'\x00\x00\x00\x07spam\x00\x08' >>> values = struct.unpack('>i4sh', data) # extract packed binary data >>> values # back to Python objects (7, b'spam', 8) Update: Python 3.2 changed the struct.pack() call to require a bytes (or bytearray) object for its "s" conversion code; using a str is an error. In 3.0 and 3.1 a str is allowed and automatically encoded to bytes as UTF-8 text—arguably too large an assumption, but 3.2 changes working and documented behavior.
Find elsewhere
🌐
Python Guides
pythonguides.com › convert-string-to-utf-8-in-python
How To Convert String To UTF-8 In Python
May 16, 2025 - By using .encode() and .decode() methods, you can easily switch between text and binary formats, making your code robust when handling files, APIs, or hardware data streams. ... In this article, I have explained how to convert string to UTF-8 in Python. I discussed three methods to accomplish this task such as using the .encode('utf-8), using the bytes() constructor, and .encode('utf-8) with error handling.
🌐
Real Python
realpython.com › python-bytes
Bytes Objects: Handling Binary Data in Python – Real Python
March 5, 2025 - After mapping each byte value into the corresponding character with Python’s chr() function, you .join() them into the string 'Real Python'. Keep in mind that this approach only works for byte values within the ASCII range. To decipher foreign Unicode characters, which may be encoded using more than one byte, you’ll have to specify the respective character encoding: ... >>> data = [0x63, 0x61, 0x66, 0xc3, 0xa9] >>> bytes(data).decode("utf-8") 'café' >>> "".join(map(chr, data)) 'café'
🌐
GeeksforGeeks
geeksforgeeks.org › python › convert-a-string-to-utf-8-in-python
Convert a String to Utf-8 in Python - GeeksforGeeks
July 23, 2025 - Converting a string to UTF-8 in Python is a simple task with multiple methods at your disposal. Whether you choose the encode method, the bytes constructor, or the str.encode method, the key is to specify the UTF-8 encoding.
🌐
Real Python
realpython.com › python-encodings-guide
Unicode & Character Encodings in Python: A Painless Guide – Real Python
May 20, 2019 - That is, the character ñ requires two bytes for its binary representation under UTF-8. Note: If you type help(str.encode), you’ll probably see a default of encoding='utf-8'. Be careful about excluding this and just using "résumé".encode(), because the default may be different in Windows prior to Python 3.6.
🌐
Python
docs.python.org › 3 › library › binascii.html
binascii — Convert between binary and ASCII
Changed in version 3.3: ASCII-only unicode strings are now accepted by the a2b_* functions. The binascii module defines the following functions: ... Convert a single line of uuencoded data back to binary and return the binary data.
🌐
Online Tools
onlinetools.com › utf8 › convert-binary-to-utf8
Convert Binary Bits to UTF8 – Online UTF8 Tools
With this tool you can easily convert raw binary bits, zeros and ones, to UTF8-encoded text. It assumes input is always 7-bit or 8-bit aligned.
🌐
GeeksforGeeks
geeksforgeeks.org › convert-binary-to-string-using-python
Convert binary to string using Python - GeeksforGeeks
April 12, 2025 - This method breaks the binary string into chunks of 8 bits and converts each chunk into a character using int() and chr() functions.
🌐
KDnuggets
kdnuggets.com › convert-bytes-to-string-in-python-a-tutorial-for-beginners
Convert Bytes to String in Python: A Tutorial for Beginners - KDnuggets
July 15, 2024 - # Sample byte object byte_data = b'Hello, World!' # Converting bytes to string string_data = str(byte_data,'utf-8') print(string_data) ... Output >>> Hello, World! Yet another method to convert bytes to string in Python is using the decode() ...