Question: Write a C++ program: Binary to Decimal Converter ( Function Required ). A sequence of binary digits represent powers of 2 that are added together

Write a C++ program: Binary to Decimal Converter (Function Required).

A sequence of binary digits represent powers of 2 that are added together to give a decimal value. For example: 1 0 1 1 0 1 represents 1 * 25 + 0 * 24 + 1 * 23 + 1 * 22 + 0 * 21 + 1 * 20 This computes out to 32 + 0 + 8 + 4 + 0 + 1 (20 = 1) or 45 decimal.

Write a program that will input a series of binary digits typed by the user and then call a function to convert the string to their decimal equivalent. For convenience limit the binary number to 16 bits. Write the decimal equivalent to the screen.

TEST CASES:

Binary Decimal
111 7
010000000000 1024
100100101 293

Remember: Read the binary number as a string type with getline. Then you can subtract 48 from each digit to get 1 or 0.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!