#include<iostream> #include<string> #include<vector> using namespace std; //例题6.3 KY26 10进制 VS 2进制 //字符串表示的大整数除法 string divide(string str, int x) { int reminder = 0; for (int i = 0; i < str.size(); i++) { int current = reminder * 10 + str[i] - '0'; str[i] = current / x + '0'; reminder = current % x; } int pos = 0; while (str[pos] == '0') { pos++; } return str.substr(pos); } string multiple(string str, int x) { int carry = 0; for (int i = str.size() - 1; i >= 0; i--) { int current = x * (str[i] - '0') + carry; str[i] = current % 10 + '0'; carry = current / 10; } if (carry != 0) { str = "1" + str; } return str; } string Add(string str, int x) { int carry = x; for (int i = str.size() - 1; i >= 0; i--) { int current = (str[i] - '0') + carry; str[i] = current % 10 + '0'; carry = current / 10; } if (carry != 0) { str = "1" + str; } return str; } int main() { string s; cin >> s; vector<int> binary; while (s.size() != 0) { int last = s[s.size() - 1]-'0'; binary.push_back(last % 2); s = divide(s, 2); } string res = "0"; for (int i = 0; i < binary.size(); i++) { res = multiple(res, 2); res = Add(res, binary[i]); } cout << res << endl; return 0; } // 64 位输出请用 printf("%lld")