python convert a binary number to a decimal number

def binToDec(num):

    temp = str(num)
    arr = []
    final = []

    for i in temp:
        arr.append(i)

    arrNums = [str(x) for x in arr]
    arrNums.reverse()

    j = 0
    for i in range(0, len(arrNums)):
        factor = arrNums[i]*(2**j)
        j += 1
        final.append(factor)

    decimal = 0
    for i in range(0, len(final)):
        decimal += final[i]

    return decimal

if __name__ == "__main__":
	num = 101000
    print(binToDec(num)) # Expected Output : 40

3
1
Joerge 115 points

                                    format(decimal ,"b")

3 (1 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to convert decimal to 32 bit unsigned binary in python integer to n bit binary python convert decimal to binary using bitwise python python module for converting binary to decimal and decimal to binary binary to decimal function in python python convert decimal to binary 32 bits binary to decimal in python how to convert a decimal number to binary number in python how to convert a decimal number to binary in python how to convert a decimal to binary in python to decimal from binary python converting int to binary to decimal python python convert binary to int how to convert deccimal to binary in python convert binary number into decimal number in python python convert a binary number to a decimal number python convert binary to decimal with 0 how to convert binary into decimal in python binary string to decimal python binary to integer python binary to decimal pytohn binary convert to decimal python binary to decimal example in python convert binary to int python python binary to decimal convert library Binary to Decimal and Back Converter in python binary to decimal 32 bit python how to convert a binary number to decimal in python python binary to int binary to decimal in python inbuilt function pythonconvert the binary number represented to a decimal number. turn binary to decimal python binary_to_decimal python python3 binary_to_decimal how to convert binary to decimal in python using inbuilt function binary string to decimal in python how to convert binary to decimal python bianry to decimal python convert binary number to integer python how to convert binary to integer in python convert bin to decimal python convert binary to integer python ibin to dec python go from binary to decimal python py convert binary to decimal binary to decimal and also perfect number in python binary to decimal and decimal to binary in python binary to decimal in python inbuilt function to convert binary to decimal in python how to change binary to decimal in python gte decimal from binary python how to convert number from binary to decimal in python Decimal binary python Decimal binary to decimal python how to convert binary number to decimal in python python program to convert binary into decimal python binary to dec how to convert binary to number in python binary number to decimal number in python binary to decimal base 10 python binary to decimal conversion class python binary to decimal class function python convert the binary number into decimal using string in python program to convert binary to decimal in python binary to decimal python using dec bin to decimal python convert a binary number to decimal in python binary converter in python convert the binary (base-2) number 1001 to decimal (base-10) in python python convert binary to base 10 binary python binary in python convert from binary to decimal python convert binary number to decimal number python convert binary to integer in python python binary to decimal binary to decimal python script convert binary to decimal in python inbuilt function in python to convert binary to decimal how to convert binary to decimal in python using terminal convert binary to decimal python bin to decimal in python binary to int python Python binary Write a Python program to convert Binary to Decimal number system. binary to decimal in pytho python convert binary to decimal how to convert from binary to decimal in python python program to convert binary to decimal change binary to decimal python python codes for binary to denary converter python function to convert binary to decimal binary to number python binary to integer in python converting binary to decimal in python how to convert binary to decimal in python binary to decimal in python integer to binary/ decimal conversion python bbinay to decimal in python binary to decimal python
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source