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 ×2 0+ 1 ×2 1+ 0 ×2 2+ 0 ×2

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 21PE
icon
Related questions
Question

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 ×2
0+ 1 ×2
1+ 0 ×2
2+ 0 ×2
3+ 1 ×2
4=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.

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
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