<p>二进制字符串2 hex</p>
<p>string get_b2hex(const char * source,int len)<br>{<br>std::string strHexPack;<br>for (int i = 0; i < len; ++i)<br>{<br>unsigned char c = source[i];<br>unsigned int nIntVal = c;<br>char hex_buf[10] = {0};<br>sprintf(hex_buf, "%02x", nIntVal);<br>strHexPack += hex_buf;<br>}<br>return strHexPack;<br>//printf("*********strHexPack:%s/n", strHexPack.c_str());<br>}</p>
<p></p>
<p>栈变量字符串2堆变量</p>
<p>const char* CopyStr(const std::string& strResult)<br>{<br>//const char* '/0'<br>const char * t_t_tempchar = (const char *)strResult.data();</p>
<p>char * charResult = (char*)malloc(sizeof(char) * strResult.size() + 1);</p>
<p>charResult[strResult.size()] = '/0';</p>
<p>strcpy(charResult, t_t_tempchar);</p>
<p>return charResult;</p>
<p>}</p>
<p>string get_b2hex(const char * source,int len)<br>{<br>std::string strHexPack;<br>for (int i = 0; i < len; ++i)<br>{<br>unsigned char c = source[i];<br>unsigned int nIntVal = c;<br>char hex_buf[10] = {0};<br>sprintf(hex_buf, "%02x", nIntVal);<br>strHexPack += hex_buf;<br>}<br>return strHexPack;<br>//printf("*********strHexPack:%s/n", strHexPack.c_str());<br>}</p>
<p></p>
<p>栈变量字符串2堆变量</p>
<p>const char* CopyStr(const std::string& strResult)<br>{<br>//const char* '/0'<br>const char * t_t_tempchar = (const char *)strResult.data();</p>
<p>char * charResult = (char*)malloc(sizeof(char) * strResult.size() + 1);</p>
<p>charResult[strResult.size()] = '/0';</p>
<p>strcpy(charResult, t_t_tempchar);</p>
<p>return charResult;</p>
<p>}</p>