/******************************************************
psHex---十六进制数组
pszStr----转换后的字符串(长度至少为3*uiHexLen)
uiHexLen---十六进制数组长度
uiBytesPerLine---每行存放多少个十六进制数(为0时不做换行控制)
返回值: > 0---转换后字符串的长度
-1 --- 参数错误
******************************************************/
int HexToString(unsigned char *psHex, unsigned char *pszStr,
unsigned int uiHexLen, unsigned int uiBytesPerLine)
{
int i = 0;
int j = 0;
if (psHex == NULL || pszStr == NULL) {
retunrn -1;
}
while (i < uiHexLen) {
sprintf(pszStr+j, "%02X ", psHex[i]);
i++;
if ((i % uiBytesPerLine) == 0 && i != 0 && uiBytesPerLine != 0) {
pszStr[j+2] = '\n';
}
j += 3;
}
pszStr[j-1] = '\n';
pszStr[j] = '0';
return j;
}