1. 程式人生 > >將string字串轉化為16進位制字串

將string字串轉化為16進位制字串

    std::string ConverToHexString(const char *in_pData,unsigned int in_uiLen)
    {
        std::string tmp_strHexValue;
        for (unsigned int i = 0; i < in_uiLen; ++i)
        {
            char tmp_szVaule[4] = { 0 };
            //SEGCC::safe_sprintf(tmp_szVaule, 4, "%02X ", (unsigned char)pmessagedate[i]);
            sprintf_s(tmp_szVaule, "%02X ", (unsigned char)in_pData[i]);
            tmp_strHexValue += tmp_szVaule;
        }
        return tmp_strHexValue;

    }

mian()

{

std::string tmp_strHexValuetest = CApiAdapter::GetInstance().ConverToHexString(pmessagedate, textlen);
CLOG_WRITE(MODULE_TAG_STRING, CSystemLog::LOG_INFO, "SendGBKData():utf8 data:%s", tmp_strHexValuetest.c_str());

}