将16进制数据转换为字符并打印
[cpp]
#include <stdio.h>
static const char NumToChar[16][2]=
{
{0,'0'},{1,'1'},{2,'2'},{3,'3'},
{4,'4'},{5,'5'},{6,'6'},{7,'7'},
{8,'8'},{9,'9'},{10,'A'},{11,'B'},
{12,'C'},{13,'D'},{14,'E'},{15,'F'}
};
char num2char(char num);
char numstr2char(char str[],char len);
int main()
{
char str[12]=
{
0xf5,0x43,0x21,0x24,
0x42,0x36,0x56,0x89,
0x26,0x48,0x97,0x18
};
numstr2char(str,12);
return 0;
}
char numstr2char(char str[],char len)
{
int i;
for(i=0;i<len;i++)
{
printf("%c",num2char((str[i]&0xF0)>>4));
printf("%c",num2char(str[i]&0x0F));
}
printf("\n");
}
char num2char(char num)
{
return NumToChar[num][1];
}
补充:软件开发 , C++ ,