我有一个查询。我有一个ascii值的字符串。我正在从Hex文件中读取。考虑字符串是“0004EB9C”。它被复制到unsigned char缓冲区中。在unsigned int中存储8个ASCII值
unsigned char buff[8] = {'0','0','0','4','E','B','9','C'}
unsigned int j = 0;
现在这个串或信息必须通过UART通信被发送。考虑这代表我执行的RAM地址。我需要将这个8字节的ascii值存储在一个无符号整数中。我没有找到一种方法可以让一些人专注于此。 复制后的输出/转换此字符串应该是这样
printf("%x",j);
这应该预先打印
Output : 0x0004EB9C
谢谢!
#包括通过直接打印 INT主(){ char data [] =“0004EB59C”; const int len = sizeof(data)/ sizeof(char)-1; int i,value [sizeof(data)/ sizeof(char)-1]; \t unsigned int j = 0; (i = 0; i = '0' &&值[I] <= '9') \t \t { \t \t \t值[I] =值[I] - '0'; \t \t \t} \t \t别的 \t \t { \t \t \t值[I] =(值[I] - 'A')+ 10; \t \t} \t j | = value [i]; } printf(“%x”,j); return 0; } 请确认..这不工作 –
user2598064
我看不出你的'价值'数组的目的,顺便说一句,你没有初始化(它有任意的数据)。只需使用'data'数组,可能将每个char复制到临时进行计算。 – ooga