About 22,500,000 results
Open links in new tab
  1. Binary to String/Text in Python - Stack Overflow

    To convert bits given as a "01"-string (binary digits) into the corresponding text in Python 3: For Python 2/3 solution, see Convert binary to ASCII and vice versa.

  2. python - How to convert string to binary? - Stack Overflow

    Oct 3, 2022 · If by binary you mean bytes type, you can just use encode method of the string object that encodes your string as a bytes object using the passed encoding type. You just need to make sure you pass a proper encoding to encode function.

  3. Convert int to binary string in Python - Stack Overflow

    Jun 3, 2023 · For those of us who need to convert signed integers (range -2**(digits-1) to 2**(digits-1)-1) to 2's complement binary strings, this works: def int2bin(integer, digits): if integer >= 0: return bin(integer)[2:].zfill(digits) else: return bin(2**digits + integer)[2:] This produces:

  4. Python | Convert String to Binary - GeeksforGeeks

    May 3, 2023 · Use the binascii.unhexlify() function to convert the hexadecimal string to binary format. Decode the binary format using the .decode() method and store the result in a variable. Print the original string and the binary format.

  5. Convert binary to string using Python - GeeksforGeeks

    Apr 12, 2025 · Explanation: int (b, 2) converts the binary string into an integer. .to_bytes (len (b) // 8, ‘big’) turns it into a byte sequence. .decode () then converts the bytes into a readable string. This method first converts the binary into a hexadecimal string, then …

  6. bin() in Python - GeeksforGeeks

    Nov 15, 2023 · In this example, we are using the bin () function to convert integer to binary string. Output. The bin () function in Python has the following syntax: Syntax: bin (a) Parameters : a : an integer to convert. Return Value : A binary string of an integer or int object. Exceptions : Raises TypeError when a float value is sent in arguments.

  7. Converting Strings to Binary in Python: A Comprehensive Guide

    Jan 20, 2025 · Understanding how to convert strings to binary in Python can be useful in various scenarios, such as data transmission, encryption, and working with low-level system components. This blog post will delve into the concepts, methods, common practices, and best practices of converting strings to binary in Python. What is a String in Python?

  8. How to Check if a String is Binary in Python? - Python Guides

    Jan 22, 2025 · Learn how to check if a string is binary in Python using `set()`, regular expressions (`re.match()`), and manual iteration. This guide includes examples.

  9. Python: 3 Ways to Convert a String to Binary Codes

    Jun 1, 2023 · This concise, example-based article will walk you through 3 different approaches to turning a given string into binary in Python. What we’ll do are: Loop through each character in the string. Convert each character to its corresponding Unicode code using the ord() function.

  10. Solved: How to Convert a String to Binary in Python

    Nov 6, 2024 · Converting a string to its binary equivalent is a task that can be tackled in various ways using Python. Below, we will explore top 5 methods to achieve this, providing practical examples along the way. Method 1: Using the encode Method. The simplest way to convert a string to a binary representation is to use the encode method.

  11. Some results have been removed
Refresh