static const char hex_table[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
std::string BytesToHexStr(const char* aInStr, int len)
{
std::string hex_str;
for (int i = 0; i < len; ++i)
{
hex_str.append(&hex_table[(aInStr[i] & 0xF0) >> 4], 1);
hex_str.append(&hex_table[aInStr[i] & 0xF], 1);
}
std::cout << hex_str << std::endl;
return hex_str;
}
网友评论