Discover answers to your questions with Westonci.ca, the leading Q&A platform that connects you with knowledgeable experts. Ask your questions and receive accurate answers from professionals with extensive experience in various fields on our platform. Discover detailed answers to your questions from a wide network of experts on our comprehensive Q&A platform.
Sagot :
Answer:
In Python:
bin = int(input("Binary Number: "))
num = str(bin)
dec = 0
for i in range(len(num)):
dec = dec + int(num[i]) * 2**int(len(num)-i-1)
print("Decimal Equivalent: "+str(dec))
Explanation:
Note that the program assumes that the user input will be valid. So, error check was done in the program
This line gets the binary number from the user
bin = int(input("Binary Number: "))
This converts the inputted number to string
num = str(bin)
This initializes decimal number to 0
dec = 0
This iterates through the string number
for i in range(len(num)):
This converts the number to decimal
dec = dec + int(num[i]) * 2**int(len(num)-i-1)
This prints the result of the conversion
print("Decimal Equivalent: "+str(dec))
See attachment for screenshots
We appreciate your visit. Hopefully, the answers you found were beneficial. Don't hesitate to come back for more information. We hope you found this helpful. Feel free to come back anytime for more accurate answers and updated information. Thank you for visiting Westonci.ca. Stay informed by coming back for more detailed answers.