十六進制轉(zhuǎn)換為字符串:
函數(shù)uti_hex2text功能為將hex字符以十六進制格式輸出到字符串text中
int uti_hex2text(unsigned char *hex, int hex_len, char *text)
{
char buffer[20];
int cnt;
for(cnt = 0; cnt < hex_len; cnt++)
{
memset(buffer, 0, 20);
sprintf(buffer, "%02x", hex[cnt]);
strcat(text, buffer);
}
return hex_len;
}
字符串轉(zhuǎn)換為十六進制:
函數(shù)uti_text2hex功能為將字符串hex以字符格式輸出到字符串text中
int uti_text2hex(char *text, unsigned char hex)
{
char buffer[20];
int cnt;
for(cnt = 0; cnt < strlen(text)/2; cnt++)
{
memset(buffer, 0, 20);
strncpy(buffer, text+cnt2, 2);
hex[cnt] = strtoul(buffer, NULL, 16);
}
return cnt;
}