create a basic python program that converts binary to number (using if statements etc)
Asking user for input of binary number
converting/calculating
printing
1ST PROCESS - ESY CODING FOR UNDERSTANDING
n = input("enter value in binary number to convert into
integer:")
# Convert n to base 2
s = int(n, 2)
print(s)
2ND PROCESS ACCORDING TO QUESTION:-
def binaryToDecimal(n):
num = n;
dec_value = 0;
# Initializing base
# value to 1, i.e 2 ^ 0
base1 = 1;
len1 = len(num);
for i in range(len1 - 1, -1, -1):
if (num[i] ==
'1'):
dec_value += base1;
base1 = base1 * 2;
return dec_value;
num = input("enter value in binary number to convert into
integer:")
print(binaryToDecimal(num));
PLEASE RATE
Get Answers For Free
Most questions answered within 1 hours.