string bytesToHexString(const char* bytes, int len) {
<span style="white-space:pre"> </span>string result = "";
<span style="white-space:pre"> </span>string temp = "0123456789ABCDEF";
<span style="white-space:pre"> </span>int index = 0;
<span style="white-space:pre"> </span>for (int i = 0; i < len; i++) {
<span style="white-space:pre"> </span>index = (bytes[i] >> 4) & 0x0f;
<span style="white-space:pre"> </span>result.append(1, temp.at(index)); // Append a character at the end of the string.
<span style="white-space:pre"> </span>index = bytes[i] & 0x0f;
<span style="white-space:pre"> </span>result.append(1, temp.at(index));
<span style="white-space:pre"> </span>}
<span style="white-space:pre"> </span>return result;
}
字节转十六进制字符串
最新推荐文章于 2024-01-15 21:45:44 发布