
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A python function named 'binarytodecimal' that converts binary numbers to their decimal equivalents. The function uses a while loop to iterate through each digit in the binary number, calculating the decimal value of each digit based on its position in the binary number using the power of 2. The function is then tested with three binary inputs: 100, 101, and 1001.
Typology: Study Guides, Projects, Research
1 / 1
This page cannot be seen from the preview
Don't miss anything!

Code def binaryToDecimal(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 print (decimal)
if name == 'main': binaryToDecimal (100) binaryToDecimal (101) binaryToDecimal (1001) output 4 5 9