Preview:
// Author : Khadiza Sultana 
#include<iostream>
 using namespace std;
  int binTodec(int binNum){
    int ans = 0, pow = 1;
    while(binNum > 0){
        int rem = binNum % 10; // accessing the last digit
        ans += rem * pow;
        binNum /= 10; // removing the last digit
        pow *= 2;
    }
    return ans;
  }

  int main(){
    int binNum;
    cin >> binNum;
    cout << binTodec(binNum) << endl;
    return 0;
  }
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter