#include<iostream>
using namespace std;
int sum(int m,int x);
int main()
{
int k=0,w,n=0,s=1,i,a,b,j=1,l=0;
char c;
cout <<"输入一个二进制数:";
for(i=7;i>=0;i--)
{ cin >>c;
if(c=='1')
n+=sum(2,i);
}
cout <<"十进制="<<n<<endl;
a=n;
while(n!=0)
{
w=n%8;
k+=w*s;
s=s*10;
n=n/8;
}
cout<<"八进制="<<k<<endl;
while(a!=0)
{
b=a%16;
a=a/16;
if(b>=10)
cout <<"十六进制="<<char(b+'A'-10);
else
{l+=b*j;
j=j*10;
cout<<"十六进制="<<j<<endl;}
}
}
int sum(int m,int x)
{
int val=1;
while (x--)
val*=m;
return val;
}
还是自己结贴