#include<iostream.h>
int first=1;
void convert(int m)
{
int binary[5];
int i;
int j;
int k;
for(i=0;m!=0;i++)
{
binary[i]=m%2;
m=m/2;
}
if(first!=1)
{
for(k=0;k<=3-i;k++)
cout<<'0';
}
first=0;
for(j=i-1;j>=0;j--)
cout<<binary[j];
}
int main()
{
char hex;
cout<<"请输入十六进制数:";
cin.get(hex);
cout<<endl<<"二进制形式为:";
while(hex!='\n')
{
if(hex=='A'||hex=='B'||hex=='C'||hex=='D'||hex=='E'||hex=='F')
convert(hex-55);
else
convert(hex-48);
cin.get(hex);
}
cout<<endl<<endl;
return 0;
}
int first=1;
void convert(int m)
{
int binary[5];
int i;
int j;
int k;
for(i=0;m!=0;i++)
{
binary[i]=m%2;
m=m/2;
}
if(first!=1)
{
for(k=0;k<=3-i;k++)
cout<<'0';
}
first=0;
for(j=i-1;j>=0;j--)
cout<<binary[j];
}
int main()
{
char hex;
cout<<"请输入十六进制数:";
cin.get(hex);
cout<<endl<<"二进制形式为:";
while(hex!='\n')
{
if(hex=='A'||hex=='B'||hex=='C'||hex=='D'||hex=='E'||hex=='F')
convert(hex-55);
else
convert(hex-48);
cin.get(hex);
}
cout<<endl<<endl;
return 0;
}