📜  没有内置函数的 Python 中的二进制到十进制 - Python 代码示例

📅  最后修改于: 2022-03-11 14:47:19.143000             🧑  作者: Mango

代码示例1
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)