Converting binary to decimal integer output

前端 未结 9 2354
暗喜
暗喜 2021-02-13 16:58

I need to convert a binary input into a decimal integer. I know how to go from a decimal to a binary:

n = int(raw_input(\'enter a number: \'))
print \'{0:b}\'.fo         


        
9条回答
  •  北恋
    北恋 (楼主)
    2021-02-13 18:00

    Try this solution:

    def binary_int_to_decimal(binary):
        n = 0
        for d in binary:
            n = n * 2 + d
    
        return n
    

提交回复
热议问题