1.16进制字符串 转无符号字节数组
unsigned char *hex2array(std::string content)
{
unsigned char temp[result_length] = { 0 };
char sz[3] = { 0 };
int len = content.length() / 2;
for (int i = 0; i < len; i++)
{
std::string strByte = content.substr(i * 2, 2);
unsigned int n;
sscanf(strByte.c_str(), "%02x", &n);
temp[i] = n;
}
return temp;
}
2.无符号字节数组 转16进制字符串
std::string array2hex(unsigned char* content)
{
TCHAR sz[2] = { 0 };
CString str =_T("");
for (int i = 0; i < length*3; i++)
{
_stprintf(sz, TEXT("%02x"), content[i]);
str += sz;
memset(sz,0,2);
}
return (LPCSTR)(CStringA)str;
}