Question
NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program
NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below.
DON'T use Function concept or any other concept except while loop,if-else.
Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly before submission. Remember: It is important that you test your code thoroughly before submission to ensure that your program is correct.
1 Program Description A binary number (or a base 2 number) is a number expressed using only the digits 0 and 1. Each individual digit of a binary number is called a bit. A string consisting of only the symbols 0 and 1 are called bit strings. Example: The binary number 1101 represents the decimal number 13, and consists of 4 bits. All data is represented by the computer as binary numbers. Thus, operations on binary numbers are extremely important in computer science. In this project you will write an application that converts binary numbers to their base 10 equivalent. In particular, your program must prompt the user to enter a binary number (represented as a bit string), and read the string from the user. Your program must then display the corresponding base 10 number to the user. The format of your programs output must match the following: (s)2 = (x)10 where s is the binary number read from the user, and x is the base 10 value of the number. No other output should be produced by your program. Example: If the user enters the binary number 1101 then your program must output: (1101)2 = (13)10
2 Converting Base 2 to Base 10 Let b = bnbn1bn2 b2b1b0 be a binary number where each bit bi is either 0 or 1. The following formula can be used to convert a given binary number to its corresponding base 10 equivalent: (b)2 = (b02 0 + b12 1 + b22 2 + + bn12 n1 + bn2 n )10 Your program must use the above formula, along with an appropriate loop, to compute the base 10 value of a given binary number read from the user. Solutions that do not include a loop that computes the above formula will receive zero credit.
3 Additional Requirements Your program must also check for the following fatal runtime error(s): 1. If the user enters a string that does not represent a valid base 2 number, then your program must print a suitable error message and exit. Invalid input, for this program, is any string that contains characters besides 0 and 1. No other errors need to be accounted for by your program. Page 1 of 2
4 Program Outline The following is a logical outline of the program requirements.
1 s = read string representing a binary number.
2
3 if s is not a bit string then
4 display error message.
5 else
6 convert s to its base 10 equivalent .
7 display result to the user.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started