代码如下,将16进制转换为2进制
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
int main()
{
int n,i;char *a,*b;
b=(char *)malloc(100000);
a=(char *)malloc(100000);
scanf("%s",a);
getchar();
for(i=0;i<strlen(a);i++)
switch(a[i])
{
case'0':strcat(b,"0000");break;
case'1':strcat(b,"0001");break;
case'2':strcat(b,"0010");break;
case'3':strcat(b,"0011");break;
case'4':strcat(b,"0100");break;
case'5':strcat(b,"0101");break;
case'6':strcat(b,"0110");break;
case'7':strcat(b,"0111");break;
case'8':strcat(b,"1000");break;
case'9':strcat(b,"1001");break;
case'A':strcat(b,"1010");break;
case'B':strcat(b,"1011");break;
case'C':strcat(b,"1100");break;
case'D':strcat(b,"1101");break;
case'E':strcat(b,"1110");break;
case'F':strcat(b,"1111");break;
}
printf("%s",b);
}
调试结果如下
望解疑,谢谢!