#include<iostream>
#include<string>
using namespace std;
int main()
{
string code = "10101100";
int result = 0; // 0000 0000
for (int i = 0; i < code.size(); i++)
{
result <<= 1;
if (code[i] == '1')
{
result |= 1;
}
}
cout << result << endl;
system("pause");
return 0;
}
结果:
172
对应的二进制刚好是 1010 1100