/*********************************************************
参数: pHexArray - 16进制数组, iArrayLength - 数组长度,
pString - 目的字符串, iStringLength - 目的字符
串长度
运行平台: VS2017
*********************************************************/
include <string.h>
include <stdio.h>
void HexArrayToString(
unsigned char *pHexArray,
unsigned char iArrayLength,
char *pString,
unsigned int iStringLength
)
{
unsigned char i = 0;
char strMid[3] = {0};
for(i=0; i<iArrayLength; i++)
{
sprintf_s(strMid, "%hhX", pHexArray[i]);
strncat_s(pString, iStringLength, strMid, sizeof strMid);
}
}
int main(void)
{
unsigned char iArray[5] = {0x12, 0x34, 0x56, 0x78, 0xAB};
char strDes[1024] = {0};
HexArrayToString(iArray, (unsigned char)(sizeof iArray), strDes, (unsigned int)(sizeof strDes));
printf("\n\n\t0x12,0x34,0x56,0x78,0xAB -> %s\n", strDes);
return 0;
}