-4
我想將一個十六進制數字轉換爲相應的ascii字符?將十六進制數組轉換爲相應的ascii字符
對於如:
arr_hex[] = {6,1,6,2,6,5,6,A,7,A}
到
arr_ascii[] = {a,b,e,j,z}
我想將一個十六進制數字轉換爲相應的ascii字符?將十六進制數組轉換爲相應的ascii字符
對於如:
arr_hex[] = {6,1,6,2,6,5,6,A,7,A}
到
arr_ascii[] = {a,b,e,j,z}
#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;
}
也許這可以幫助你:http://stackoverflow.com/q/16519056/3933332 – Rizier123 2014-11-25 10:15:54
我假設你的意思'0xA',而不是'A'。無論如何,一個shift + add應該可以做到。 – Michael 2014-11-25 10:16:40
這是一個不好的事情。你爲什麼不用'int arr_hex [] = {0x61,0x62,0x65,0x6A,0x7A}'這樣的東西? – bitcell 2014-11-25 10:16:43