废话不多说,直接上代码
void HexToString(char *dst,const unsigned char *src,int sLen) // hex to ASCII
{
const char* hexDigits = "0123456789ABCDEF";
int a,b,j = 0,k = 0;
char c;
for(k = 0; k < sLen; k++)
{
c = src[k];
if((c & 0x80) > 0) // c > 128
{
a = c & 0x0F;
b = c & 0xF0;
dst[j++] = hexDigits[(a+b)/16];
dst[j++] = hexDigits[a%16];
}
else
{
dst[j++] = hexDigits[c/16];
dst[j++] = hexDigits[c%16];
}
}
dst[j] = '\0';
}
网友评论