一组字符串转换16进制

mac2025-01-29  30

void char_change_Hex(uint8_t *str,uint8_t *ptr) { unsigned char i,temp[12];uint8_t buf[6]; for(i=0;i<12;i++) { if(str[i]>=‘0’ && str[i]<=‘9’) temp[i]=str[i]-‘0’; else if(str[i]>=‘A’ && str[i]<=‘F’) temp[i]=str[i]-‘A’+0x0A; else if(str[i]>=‘a’ && str[i]<=‘f’) temp[i]=str[i]-‘a’+0x0a; else { NRF_LOG_WARNING(“error not 16hex\n”); return ; } }

buf[0] = temp[0]*16 + temp[1]; buf[1] = temp[2]*16 + temp[3]; buf[2] = temp[4]*16 + temp[5]; buf[3] = temp[6]*16 + temp[7]; buf[4] = temp[8]*16 + temp[9]; buf[5] = temp[10]*16 + temp[11]; strcpy(ptr,buf);

// printf(" 0x%x %x %x %x %x %x\n",buf[0],buf[1],buf[3],buf[3],buf[4],buf[5]); }

最新回复(0)