I want to write a function that takes a string of Binary and returns the result as Decimal.
I've written some code but if I didn't know it needed to be a string of Binary instead of just the numbers. Is there a way to change the code so it takes the string? I don't want to turn the binary to float, I want to turn it into decimal.
#Binary to Decimal
def bi_to_dec(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