16,473
社区成员
发帖
与我相关
我的任务
分享
unsigned char * HexToStr(unsigned char *szOutStr,size_t szlen,unsigned char *hex,size_t size)
{
unsigned char ch,shiftch;
unsigned char * src = hex;
unsigned char * des = szOutStr;
if ( szOutStr == NULL || hex == NULL )
return NULL;
//buffer size
if ( (szlen - 1) < size * 2)
return NULL;
while ( size-- > 0 )
{
ch = *src++;
shiftch = ch >>4;
if ( shiftch >= 0x0 && shiftch <= 0x09 )
*des++ = shiftch + '0';
if ( shiftch >= 0x0a && shiftch <= 0x0f )
*des++ = shiftch + '1';
shiftch = ch & 0x0f;
if ( shiftch >= 0x0 && shiftch <= 0x09 )
*des++ = shiftch + '0';
if ( shiftch >= 0x0a && shiftch <= 0x0f )
*des++ = shiftch + '1';
}
*des = 0;
return szOutStr;
}