http://www.cnblogs.com/nio-nio/p/3309367.html
/*
// C prototype : void StrToHex(BYTE *pbDest, BYTE *pbSrc, int nLen)
// parameter(s): [OUT] pbDest - 输出缓冲区
// [IN] pbSrc - 字符串
// [IN] nLen - 16进制数的字节数(字符串的长度/2)
// return value:
// remarks : 将字符串转化为16进制数
*/
void StrToHex(BYTE *pbDest, BYTE *pbSrc, int nLen)
{
char h1,h2;
BYTE s1,s2;
int i; for (i=; i<nLen; i++)
{
h1 = pbSrc[*i];
h2 = pbSrc[*i+]; s1 = toupper(h1) - 0x30;
if (s1 > )
s1 -= ; s2 = toupper(h2) - 0x30;
if (s2 > )
s2 -= ; pbDest[i] = s1* + s2;
}
} /*
// C prototype : void HexToStr(BYTE *pbDest, BYTE *pbSrc, int nLen)
// parameter(s): [OUT] pbDest - 存放目标字符串
// [IN] pbSrc - 输入16进制数的起始地址
// [IN] nLen - 16进制数的字节数
// return value:
// remarks : 将16进制数转化为字符串
*/
void HexToStr(BYTE *pbDest, BYTE *pbSrc, int nLen)
{
char ddl,ddh;
int i; for (i=; i<nLen; i++)
{
ddh = + pbSrc[i] / ;
ddl = + pbSrc[i] % ;
if (ddh > ) ddh = ddh + ;
if (ddl > ) ddl = ddl + ;
pbDest[i*] = ddh;
pbDest[i*+] = ddl;
} pbDest[nLen*] = '\0';
}