Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/*3. Write a program that will convert a string of binary digits to the decimal equivalent. For convenience limit the binary number to 16 bits.

/*3. Write a program that will convert a string of binary digits to the decimal equivalent. For convenience limit the binary number to 16 bits. Write the decimal equivalent to the screen. Here are some examples:

BINARY DECIMAL

111 7

01000000000

100100101

HINT: Read the binary number as a string type. The ASCII value for the number "1" is 49. An easy way to convert the ASCII to an integer is to subtract 48. e.g. bit = (digit - 48) wher bit is of type int.*/

#include "stdafx.h" #include #include #include #include

using namespace std; int main(void) { string binary1 = "111"; string binary2 = "01000000000"; string binary3 = "100100101" int length = 0, i = 0, formula;

int digit; char ch1;

length = binary1.length(); while (i <= length) { cin.get(ch1); cout << ch1; //i want to be able to read each character and use the formula to convert to binary

//please advise

thanks

}

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions