gpt4 book ai didi

将十六进制值数组转换为相应的 ascii 字符

转载 作者:行者123 更新时间:2023-11-30 21:21:14 24 4
gpt4 key购买 nike

我想将十六进制数字数组转换为其相应的 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;
}

关于将十六进制值数组转换为相应的 ascii 字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27123921/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com