Problem 2 A number in base 2 (binary) is a number such that each of its digits is 0 or 1. To convert from binary to decimal (base 10), the digits starting from the right are multiplied by powers of 2 (starting at 0) and added. For example, the value in decimal of 10011 is calculated as follows: 1 x20+ 1 x21+ 0 x22+ 0 x23+ 1 x24=19 Write a program that reads from the user a 5-digit integer representing a value in binary and displays its equivalent value in decimal. Note that if the user enters an integer which digits are other than 0 or 1, the program displays a message stating that the number is not valid. Sample Run 1: Enter a 5-digit integer made of Os and 1s: 10011 10011 in decimal is 19

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter4: Selection Structures
Section4.3: Nested If Statements
Problem 7E
icon
Related questions
Question
Solve using java language, while loop is not allowed
Problem 2
A number in base 2 (binary) is a number such that each of its digits is 0 or 1. To convert from
binary to decimal (base 10), the digits starting from the right are multiplied by powers of 2
(starting at 0) and added. For example, the value in decimal of 10011 is calculated as follows:
1x20+ 1 x21+ 0 x22+ 0 x23+ 1 x24=19
Write a program that reads from the user a 5-digit integer representing a value in binary and
displays its equivalent value in decimal. Note that if the user enters an integer which digits are
other than 0 or 1, the program displays a message stating that the number is not valid.
Sample Run 1:
Enter a 5-digit integer made of Os and 1s: 10011
10011 in decimal is 19
Sample Run 2:
Enter a 5-digit integer made of Os and 1s: 13001
13001 is not valid
Transcribed Image Text:Problem 2 A number in base 2 (binary) is a number such that each of its digits is 0 or 1. To convert from binary to decimal (base 10), the digits starting from the right are multiplied by powers of 2 (starting at 0) and added. For example, the value in decimal of 10011 is calculated as follows: 1x20+ 1 x21+ 0 x22+ 0 x23+ 1 x24=19 Write a program that reads from the user a 5-digit integer representing a value in binary and displays its equivalent value in decimal. Note that if the user enters an integer which digits are other than 0 or 1, the program displays a message stating that the number is not valid. Sample Run 1: Enter a 5-digit integer made of Os and 1s: 10011 10011 in decimal is 19 Sample Run 2: Enter a 5-digit integer made of Os and 1s: 13001 13001 is not valid
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning