Subscribe Us

Responsive Advertisement

Advertisement

any base to decimal conversion

 

any base to decimal conversion

by ujjal roy




//any base to decimal

#include<bits/stdc++.h>

using namespace std;

#define ll long long int

#define endl "\n"

ll to_decimal(string s,ll b)

{

    ll power=1;

    ll ans;

    ans=0;

    for(ll i=s.size()-1;i>=0;i--)//111

    {

        ans+=(s[i]-'0')*power;

        power*=b;

    }

    return ans;

}

int main()

{

     ios_base::sync_with_stdio(0);

     cin.tie(0);

     cout.tie(0);


    string s;

    cin>>s;

    ll r=to_decimal(s,2);

   cout<<r<<endl;










    return 0;


}


Post a Comment

0 Comments