c++ buf 转 hex,内存转十六进制文本

int BufToHex(char* pBuf, int iLen, string& strOut)
{
  strOut.clear();
  if (NULL == pBuf || iLen < 1)
  {
    return TRUE;
  }

  char szTmp[4] = { 0 };
  strOut.reserve(128 + iLen * 3);
  for (int i = 0; i < iLen; i++)
  {
    ZeroMemory(szTmp, sizeof(szTmp));
    sprintf(szTmp, "%02X ", static_cast<BYTE>(pBuf[i]));
    strOut.append(szTmp);
  }

  return TRUE;
}

posted @ 2020-10-22 21:17  龙马8586  阅读(701)  评论(0编辑  收藏  举报