Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Binary to decimal in Python without inbuilt function

binary_num = int(input("Enter the Binary Number: "))
dec_num = 0
m = 1
length = len(str(binary_num))

for k in range(length):
    reminder = binary_num % 10
    dec_num = dec_num + (reminder * m)
    m = m * 2
    binary_num = int(binary_num/10)

print("Equivalent Decimal Value = ", dec_num)
Comment

Python Code to Convert Binary to Decimal Without Inbuilt Function

Python Code to Convert Binary to Decimal Without Inbuilt Function
binary_str = input('Enter a Binary number to convert it to Decimal: ')

digit_list = list(binary_str)
digit_list.reverse()
sum = 0

for digit in (range(len(digit_list))):
    sum = sum + int(digit_list[digit]) * pow(2, digit)
print(sum)
Comment

Python Code to Convert Binary to Decimal With Inbuilt Function

binary_str = input("Enter a Binary number to convert it to Decimal :")

decimal_num = int(binary_str, 2)
print(decimal_num)
Comment

PREVIOUS NEXT
Code Example
Python :: post list python 
Python :: import pyautogui 
Python :: discord bot python example 
Python :: is in array python 
Python :: How to take multiple input form python 
Python :: how to check if python is installed on mac 
Python :: python curses for windows 
Python :: WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. 
Python :: function wrapper with variable number of arguments python 
Python :: google assistant in windows 10 
Python :: write string python 
Python :: delete from list in python 
Python :: del list python 
Python :: largest number python 
Python :: how to negate a boolean python 
Python :: multiple input to list 
Python :: Appending rows to a DataFrame 
Python :: python append row to 2d array 
Python :: from django.core.management import execute_from_command_line ImportError: No module named django.core.management 
Python :: decision tree classifier python code for visualization 
Python :: dtype array 
Python :: unsupervised knn 
Python :: numpy python 3.10 
Python :: casting in python 
Python :: get guild from a channel discord py 
Python :: reading from a file in python 
Python :: difference between set and list in python 
Python :: i have two versions of python installed mac 
Python :: head first python 
Python :: python single line comment 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =