基础知识:进制转换

#include <iostream>
using namespace std;

//string类除以2
void string_chu_2(string& s) {
    string t;
    int a = 0; //余后值
    for (int i = 0; i < s.size(); i++) {
        //除
        char c;
        c = (a * 10 + s[i] - '0') / 2 + '0';
        t = t + c;
        //余
        a = (a * 10 + s[i] - '0') % 2;
    }
    int i = 0;
    if (t != "0")
        while (t[i] == '0')
            i++;
    t.erase(0, i);
    s = t;
}

int main() {
    string a;//输入的数字
    while (cin >> a) {
        if (a == "0") {
            cout << 0 << endl;
            continue;
        }
        string s;//二进制表示
        while (a != "0") {
            char c;
            if ((a[a.size() - 1] - '0') % 2 == 0)
                c = '0';
            else
                c = '1';
            s = c + s;
            string_chu_2(a);
        }
        cout << s << endl;
    }
    return 0;
}