我想将十六进制数字数组转换为相应的ascii字符?
例如:
arr_hex[] = {6,1,6,2,6,5,6,A,7,A}
到
arr_ascii[] = {a,b,e,j,z}
答案 0 :(得分:2)
#include <stdio.h>
#define A 10
#define B 11
#define C 12
#define D 13
#define E 14
#define F 15
int main(void){
int arr_hex[] = {6,1,6,2,6,5,6,A,7,A};
int size = sizeof(arr_hex)/sizeof(*arr_hex);
char arr_ascii[size/2];
int i, j;
for(j=i=0; j < size/2; i+=2){
printf("%c", arr_ascii[j++] = arr_hex[i]*16 + arr_hex[i+1]);
}
printf("\n");
return 0;
}