字节转十六进制字符串

string bytesToHexString(const char* bytes, int len) {
  string result = "";
  string temp = "0123456789ABCDEF";
  int index = 0;
  for (int i = 0; i < len; i++) {
    index = (bytes[i] >> 4) & 0x0f;
    result.append(1, temp.at(index));  // Append a character at the end of the string.
    index = bytes[i] & 0x0f;
    result.append(1, temp.at(index));
  }
  return result;
}


posted @ 2014-08-26 21:29  bgmind  阅读(220)  评论(0编辑  收藏  举报