 <p>Hint: Since you are using C++, look up the <code>hex</code> I/O Manipulator:<br> <a href="http://en.cppreference.com/w/cpp/io/ios_base/fmtflags" rel="nofollow">http://en.cppreference.com/w/cpp/io/ios_base/fmtflags</a></p> <p>If you want to use the C style I/O, look up the <code>printf</code> modifier, <code>%x</code>, as in <code>"0x%02X "</code>.</p> <p><strong>Edit 1:</strong><br> To save in a variable, using C style functions:</p> <pre><code>char hex_buffer[256]; unsigned int i; for (i = 0; i &lt; size; i++) { snprintf(hex_buffer, sizeof(hex_buffer), "%x ", buffer[i]); } </code></pre> <p>Using C++, lookup the <code>std::ostringstream</code>: </p> <pre><code> std::ostring stream; for (unsigned int i = 0; i &lt; size; ++i) { stream &lt;&lt; hex &lt;&lt; buffer[i] &lt;&lt; " "; } std::string my_hex_text = stream.str(); </code></pre>