#include<iostream>
using std::cout;
using std::cin;
int main()
{
int a, b, c, i, x, bin, oct, hex, x_bin, x_oct, x_hex;
cout<<"Enter a number(1~256)\n";
cin>>x;
a=256;
b=64;
c=256;
x_bin=x_oct=x_hex=x;
//=====================分隔線===================
cout<<"The Binary:";
for(i=1;i<=9;i++)
{
bin=x_bin/a;
x_bin=x_bin%a;
a=a/2;
cout<<bin;
}
cout<<"\n";
//=====================分隔線===================
cout<<"The Octal: ";
for(i=1;i<=3;i++)
{
oct=x_oct/b;
x_oct=x_oct%b;
b=b/8;
cout<<oct;
}
cout<<"\n";
//=====================分隔線===================
cout<<"The hex: ";
for(i=1;i<=3;i++)
{
hex=x_hex/c;
x_hex=x_hex%c;
c=c/16;
if(hex==10) cout<<"A";
else if(hex==11) cout<<"B";
else if(hex==12) cout<<"C";
else if(hex==13) cout<<"D";
else if(hex==14) cout<<"E";
else if(hex==15) cout<<"F";
else cout<<hex;
}
cout<<"\n";
}
afjsp:哇~~還把程式po上來呢....真有心哦...3/30
[ Last edited by afjsp on 2005-3-30 at 01:31 PM ] |