Decode it.

>>> b'a string'.decode('ascii')
'a string'

To get bytes from string, encode it.

>>> 'a string'.encode('ascii')
b'a string'
Answer from falsetru on Stack Overflow
๐ŸŒ
LabEx
labex.io โ€บ tutorials โ€บ python-how-to-parse-binary-string-values-462157
How to parse binary string values | LabEx
Python provides several methods for bit-level operations: ## Bitwise operations a = 0b1010 ## 10 in decimal b = 0b1100 ## 12 in decimal ## Bitwise AND print(a & b) ## Outputs: 8 (0b1000) ## Bitwise OR print(a | b) ## Outputs: 14 (0b1110) ## Bitwise XOR print(a ^ b) ## Outputs: 6 (0b0110) When working with binary strings in LabEx programming environments, consider: ... By understanding these binary basics, you'll be well-prepared to parse and manipulate binary string values effectively in Python.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ convert-binary-to-string-using-python
Convert binary to string using Python - GeeksforGeeks
July 12, 2025 - Finally, join() combines all characters into a single string. In this approach, the whole binary string is first turned into an integer. Then itโ€™s converted to bytes and finally decoded into a string.
๐ŸŒ
Quora
quora.com โ€บ How-do-I-parse-binary-files-using-Python-What-should-I-know-about-binary-files-before-parsing
How to parse binary files using Python? What should I know about binary files before parsing - Quora
Answer: Things to know about binary files in any language: 1. Do not trust them. If a field is supposed to be a length of the following string, check it. It cannot be negative, zero, or bigger than the available data. If it is supposed to be a null terminated string, make sure it ends with a nul...
๐ŸŒ
PyPI
pypi.org โ€บ project โ€บ parse-binary-file
parse-binary-file ยท PyPI
pip install parse-binary-file Copy PIP instructions ยท Install with python -m pip install parse_binary_file
๐ŸŒ
Unh
vislab-ccom.unh.edu โ€บ ~schwehr โ€บ rt โ€บ python-binary-files.html
Chapter XXX: Python - parsing binary data files
We now have 22712 bytes in a string. We can start using the python struct module to begin decoding the file. Struct is designed just for our needs - going between python and binary data. We specify letter codes and python does the hard work of figuring out how to decode the bytes from the type.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help
Program that converts the Binary string to the Numeric - Python Help - Discussions on Python.org
August 13, 2023 - b=โ€˜1111โ€™ i=0 while b: i = i*2+(ord(b[0])-ord(โ€˜0โ€™)) b=b[1:] print(โ€˜Decimal valueโ€™+ str(i) Can anyone explain what does ord(b[0]) do here?
๐ŸŒ
PyPI
pypi.org โ€บ project โ€บ binary-parser
binary-parser ยท PyPI
>>> import binary_parser >>> binary_parser.parse_to_num('1011') '11' >>> binary_parser.parse_to_num('000') '0' >>> binary_parser.parse_to_num('01') '1' Arguments passed can be a string or an integer type.
      ยป pip install binary-parser
    
Published: Feb 26, 2022
Version: 0.0.4
Find elsewhere
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ built-in-methods โ€บ convert-binary-string-to-normal-string
4 ways to Convert a Binary String to a Normal String - AskPython
April 23, 2023 - Related: Read this article to know more about the conversion of integers to binary. The bin() function is a built-in Python function used to obtain the binary representation of an integer.
๐ŸŒ
Quora
quora.com โ€บ How-do-you-convert-a-binary-to-a-string-in-Python
How to convert a binary to a string in Python - Quora
Answer (1 of 2): def BinaryToDecimal(binary): binary1 = binary decimal, i, n = 0, 0, 0 while(binary != 0): dec = binary % 10 decimal = decimal + dec * pow(2, i) binary = binary//10 i += 1 return (decimal) # Driver's code # initializing binary data bin_data ='100011111001011100101110101...
๐ŸŒ
Fluentpython
fluentpython.com โ€บ extra โ€บ parsing-binary-struct
Parsing binary records with struct | Fluent Python, the lizard book
Handle null-terminated C string: split once on b'\0', then take the first part. Decode bytes into str. Open and read the whole file in binary mode; data is a bytes object.
๐ŸŒ
w3reference
w3reference.com โ€บ blog โ€บ regular-expression-parsing-a-binary-file
Python 3: How to Parse Binary Files with Regular Expressions โ€“ Fixing 'TypeError: can't use a string pattern on a bytes-like object'
Regex is powerful for variable patterns (e.g., searching for a magic number in a large binary), but not ideal for rigid, formatted data (e.g., headers with fixed-size integers). For such cases, use Pythonโ€™s struct module alongside regex: import struct # Parse a 4-byte little-endian integer (better than regex for fixed types) data_size = struct.unpack("<I", data_size_bytes)[0] # <I = little-endian unsigned int
๐ŸŒ
Milddev
milddev.com โ€บ python-binary-to-string
Python Binary to String Guide
July 28, 2025 - Converting binary data to strings in Python is straightforward once you understand encodings, byte order, and the right tools. Start with the built-in bytes.decode() for UTF-8 tasks and move to the codecs module for more exotic formats. Manual bitwise methods offer precise control in niche cases. Always handle errors gracefully and profile large conversions for speed. With these techniques in your toolkit, you can read files, parse streams, and interact with hardware confidently.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ working-with-binary-data-in-python
Working with Binary Data in Python - GeeksforGeeks
June 22, 2020 - This means that before Python3 we could treat a set of bytes as a string and work from there, this is not the case now, now we have a separate data type, called bytes. This data type can be briefly explained as a string of bytes, which essentially means, once the bytes data type is initialized it is immutable. ... bytestr = bytes(b'abc') # initializing a string with b # makes it a binary string print(bytestr) print(bytestr[0]) bytestr[0] = 97