二进制转换问题
“转换二进制”;这是我做的,运行时总是负数,我已经看不清楚了,大家帮我看看吧,改一改,谢谢啦~~~#include<iostream>
#include<fstream>
#include<sstream>
#include<vector>
#include<cmath>
using namespace std;
//---------------------------------------------------
int main()
{
cout<<"输入要转换的二进制数 : "<<endl;
string s;
vector<int> x;
cin>>s;
istringstream sin(s);
int sum = 0;
for(int a ;sin>>a;)
x.push_back(a);
int d=x.size();
for(int i = 0; i<=d ;++i)
{
double o=pow(2.0,d-i);
sum+=(x[i] * o);
}
cout<<sum<<endl;
return 0;
}