Computer Science, asked by prabachanthapa4, 1 year ago

Write a program to accept a binary number and convert it into its decimal equivalent.

Answers

Answered by pokemon2000anoozvoy2
1
#include <iostream>#include <cmath>#include <conio.h>#include <sstream>
using namespace std;

int main ()   { string inte; int cc[100] , lo=0 , ex_l=0; cout << "Enter the Binary digit :   "; getline(cin , inte);

 for ( ; lo < inte.length()  ; lo++)  {    string j;    j = inte[lo];    stringstream convert(j);    convert >> cc[lo];       } cout << "procedure :  "; int stro , str2 , clone; clone = inte.length(); for ( ; ex_l < inte.length() ; ex_l++ )  { stro  =  cc[ex_l] * (pow (2 , clone-1  ));        str2 = str2 + stro; if ( ex_l  == inte.length()-1)  { cout << cc[ex_l] << "*" << "2" << "^" << clone-1; } else { cout << cc[ex_l] << "*" << "2" << "^" << clone-1 << " + "; } clone -= 1; } cout << endl << endl << endl << "Decimal :  "<<str2; getch(); }
Similar questions