The part that converts the binary is int. From the documentation:

if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in radix base.

This means that int accepts a string representing an integer, that you tell it the base of. E.g. here we give it "11", and tell it this is in base 2, so it returns the integer 3 in decimal.

>>> int("11", 2)
3

Note that when supplying the base argument, you have to give a string:

>>> int(11, 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: int() can't convert non-string with explicit base

And you can't use digits that are invalid in the given base:

>>> int("21", 2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 2: '21'
Answer from Calum You on Stack Overflow
🌐
Scribd
scribd.com › document › 887675681 › Binary-to-Decimal-convert
Python 8-bit Binary to Decimal Tool | PDF | Programming | Computer Program
Binary-to-Decimal convert - Free download as Word Doc (.doc / .docx), PDF File (.pdf), Text File (.txt) or read online for free. The document details a Python program designed to convert 8-bit binary numbers to decimal and vice versa, focusing on user-friendly interaction and robust input validation.
Discussions

Python 3.6 converting 8 bit binary to decimal - Stack Overflow
I am making a Python code in Python 3,6 that will prompt the user to input either 2 decimals up to 255 or an 8 bit binary number with the conversion to decimal, getting the user to input the 2 stan... More on stackoverflow.com
🌐 stackoverflow.com
Write a program in Python to convert an 8-bit binary number to a decimal number. This application will use loops and conditions to accomplish the task. If the input is less than or greater than 8 bits or anything other than 0s or 1s, you can exit with an error message. Inputs Your Python program should accept an 8 bit binary number. Output Your program
"""Python program to input 8-bit binary number and convert it to decimal equivalent""" import sys def read_binary_number(): """ Read user binary string from user, if length is greater than 8 bits or if it contains character other than …View the full answer More on chegg.com
🌐 chegg.com
1
November 19, 2017
python - Converting binary to decimal integer output - Stack Overflow
2014-02-13T22:01:58.833Z+00:00 ... works great, verified using the online number convertor here - randomtools.io/binary-to-decimal 2022-04-30T10:31:29.537Z+00:00 ... Save this answer. ... Show activity on this post. ... ps: I understand that the author doesn't want a built-in function. But this question comes up on the google feed even for those who are okay with in-built function. ... Python ... More on stackoverflow.com
🌐 stackoverflow.com
binary - using python to convert integer to 8bit binarey - Stack Overflow
Im working on a program which converts binary into integers (easy enough) however I then need to convert the integers back into 8bit binary representation. I have had a look, and I can do it More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
medium.com › @pivajr › pythonic-tips-how-to-convert-binary-to-decimal-in-python-9f781b029130
Pythonic Tips: How to Convert Binary to Decimal in Python | by Dilermando Piva Junior | Medium
May 12, 2025 - The int() function is one of the most direct ways to convert a binary number (as a string) into a decimal. You just need to pass the string and specify the base (2 for binary). ... Python interprets the string and returns the corresponding decimal ...
🌐
Python Forum
python-forum.io › thread-6617.html
Converting an 8-bit binary to decimal WITHOUT the shortcuts
November 30, 2017 - Hey everyone, I am trying to self-teach myself in python and I was wondering. Is there a way to convert an 8-bit binary to decimal without using the shortcuts? I don't have any code for this yet because I wouldn't even know where to start beside get ...
Find elsewhere
🌐
3Ri Technologies
3ritechnologies.com › home › master python conversions: binary to decimal and decimal to binary
How to Convert Binary to Decimal in Python - Pune
November 7, 2025 - ‘0’ or ‘1’ should be the characters in the string that is used as the input to represent this number. The second and third kinds of text can be converted to a decimal integer using Python’s int() method.
🌐
Note.nkmk.me
note.nkmk.me › home › python
Convert Binary, Octal, Decimal, and Hexadecimal in Python | note.nkmk.me
May 19, 2023 - For example, use 0b1111 (= 0xf) for 4-bit, 0xff for 8-bit, and 0xffff for 16-bit representations. ... You can use the built-in function int() to convert a binary, octal, or hexadecimal string into a number.
🌐
CSology
csology.co.uk › home › binary › convert binary to decimal (binary conversion)
Convert Binary to Decimal (Binary Conversion) | CSology Guides
August 18, 2025 - Place order: Always line up 128 64 32 16 8 4 2 1 before adding. // Pseudocode INPUT bits (string of 0s and 1s) value ← 0 FOR i FROM 0 TO LEN(bits)-1 bit ← INT(bits[i]) weight ← 2^(LEN(bits)-1 - i) value ← value + (bit * weight) OUTPUT value · def binary_to_decimal(bits: str) -> int: value = 0 n = len(bits) for i, ch in enumerate(bits): bit = 1 if ch == '1' else 0 weight = 1 << (n - 1 - i) # 2^(n-1-i) value += bit * weight return value print(binary_to_decimal("11010101")) # 213
🌐
Binary To Decimal
binarytodecimal.net › home › 8-bit binary to decimal converter
8-Bit Binary to Decimal Converter
September 5, 2026 - Convert 8-bit binary to decimal instantly. Enter any 8-bit binary value from 00000000 to 11111111 and get the decimal result, place-value calculation, powers of 2, examples, chart, and FAQs.
🌐
Reddit
reddit.com › r/pythontips › convert decimal input to 8 bit binary
r/pythontips on Reddit: Convert decimal input to 8 bit binary
October 29, 2023 -

Hi all i'm very new to coding (a few weeks) and Python and was wondering if there is a way to get an input of a decimal number and convert it to 8 bit binary. Currently using the Thonny IDE

🌐
Caesar Cipher
caesarcipher.org › overview › converters › binary to decimal converter
Binary to Decimal Converter & Table — Free Online Tool | Caesar Cipher
March 19, 2026 - # Convert binary string to decimal ... 8-bit def signed_binary_to_decimal(binary_str, bits=8): value = int(binary_str, 2) if value >= 2**(bits - 1): value -= 2**bits return value print(signed_binary_to_decimal("11111001")) # -7 ...
🌐
Anwebtools
anwebtools.com › home › converters › 8 bit binary to decimal
8 bit binary to decimal
converts binary codes or numbers by 8 bit binary to decimal for decimal numbers very easy and quickly with copy converted Numbers as you needs
🌐
Python Guides
pythonguides.com › python-convert-binary-to-decimal
How to Convert Binary to Decimal in Python
January 27, 2026 - If you try to convert a string that isn’t a valid binary (like “1021”), Python will throw a ValueError. I always recommend wrapping your conversion logic in a try-except block to prevent your application from crashing. binary_input = "10102" # Invalid binary try: decimal_output = int(binary_input, 2) print(decimal_output) except ValueError: print("Error: The provided string is not a valid binary number.")
🌐
CalculatorHub
calculatorhub.com › home › tools › binary to decimal calculator
Binary to Decimal Calculator: Binary, Decimal, Hex, Octal Converter - CalculatorHub
June 14, 2026 - Converting between binary and decimal is a core skill for computer science students, network engineers, and programmers working at the bit level. This calculator converts binary strings to decimal, hexadecimal, and octal in both directions. For binary inputs, it also shows the 8-bit unsigned range (0-255) note and the two's complement signed interpretation for 8-bit values.