#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
int n, tmp;
char a[10001],b[10001];
int i,k;
scanf("%d",&n);
while(n--)
{
scanf("%s",a);
k = 0;
tmp = 0;
for( i=strlen(a)-4 ; (i+4)>0 ; i-=4)
{
if(i>=0) tmp = (a[i]-'0')*8 + (a[i+1]-'0')*4 + (a[i+2]-'0')*2 + (a[i+3]-'0');
else if((i+1)>=0) tmp = (a[i+1]-'0')*4 + (a[i+2]-'0')*2 + (a[i+3]-'0');
else if((i+2)>=0) tmp = (a[i+2]-'0')*2 + (a[i+3]-'0');
else if((i+3)>=0) tmp = (a[i+3]-'0');
if( tmp>=0 && tmp<=9 ) b[k++] = '0' + tmp ;
else b[k++] = (tmp-10) + 'A';
}
for( i=k-1 ; i>=0 ; i--)
printf("%c",b[i]);
printf("\n");
}
system("PAUSE");
return 0;
}
第3章练习题--3--二进制转换为十六进制--2798
最新推荐文章于 2023-06-04 22:33:18 发布