#include <iostream>
#include <windows.h>
#include <string>
using namespace std;
int main() {
    string str;
    int p = 1;
    int s = 0;

    cout << "请输入一个二进制数:";
    cin >> str;

    for (int i = str.length() - 1; i >= 0; i--) {
        int x = str[i] - '0';
        s += x * p;
        p *= 2;
    }
    cout << s << endl;
    system("pause");
    return 0;
}

 

posted on 2022-08-11 12:00  wshidaboss  阅读(1115)  评论(0编辑  收藏  举报