def BinaryDecimal(n):  #user-defined function
          num, dec, base = n, 0, 1
          temp = num
          while(temp):
              digit = temp % 10
              temp = int(temp / 10)
              dec += digit * base
              base = base * 2
          return dec
      # take inputs
      num = int(input('Enter a binary number: '))
      # display result
      print('The decimal value is =', BinaryDecimal(num))
      
      Python language logo

      Binary to Decimal

      beginner
      basicMaths
      function

      Convert Binary to Decimal in Python using while loop

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.