#include <stdio.h>
//hexadecimal to binary
int main()
{
char Table[16][5] = {"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};
char Str[] = "1D 00 04 34 4C 98";
char *p = NULL;
p = Str;
while(*p){
if(*p == ' '){
p++;
continue;
}
if('0' <= *p && *p <= '9')
printf("%s",Table[*p-'0']);
else
printf("%s",Table[*p-'A'+10]);
p++;
}
printf("\n");
return 0;
}输出结果:000111010000000000000100001101000100110010011000
本文介绍了一个简单的C语言程序,该程序能够将输入的十六进制字符串转换为对应的二进制表示形式。通过查找表的方式,程序逐字符读取十六进制数并输出相应的四位二进制数。
1万+

被折叠的 条评论
为什么被折叠?



