At Westonci.ca, we provide reliable answers to your questions from a community of experts. Start exploring today! Get quick and reliable answers to your questions from a dedicated community of professionals on our platform. Get immediate and reliable solutions to your questions from a community of experienced professionals on our platform.

Write a program in your favorite language (e.g., C, Java, C , etc.) to convert max. 32 bit numbers from binary to decimal. The user should type in an unsigned binary number. The program should print the decimal equivalent. You should write a program from scratch that performs the conversion, please do not use built in functions. Please provide a screenshot of your program running on these values: 111011012 110000110011110101110101011101012 Please also include your source code together with your answers to assignment questions.

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

View image MrRoyal
View image MrRoyal
We appreciate your time on our site. Don't hesitate to return whenever you have more questions or need further clarification. Thank you for visiting. Our goal is to provide the most accurate answers for all your informational needs. Come back soon. Thank you for visiting Westonci.ca. Stay informed by coming back for more detailed answers.