binary to decimal in cpp

technical talkiess
0

 // Online C++ compiler to run C++ program online


#include <iostream>


#include <math.h>


using namespace std;


int main() {


    int a;


    cout<<"Enter the number";


    cin>>a;


    int answer = 0;


    int i =0;


    while(a!=0){


      int bit = a % 10;

      if(bit == 1){

         answer = pow(2,i) + answer;

      }

      a = a/10;


      i++;


    }


     cout<<answer;


    return 0;


}

Tags

Post a Comment

0Comments

Thanks you for commenting your questions. I will see question and respond you.

Post a Comment (0)