title: C++ convert UTF8 string to hexadecimal and vice versa
body: <p>It took time looking as utf8 convert string to hexadecimal string, and backwards
  I found some examples and possible solutions, but all work well only without special characters.
  I have a folowing :</p>
  <p>string in=&quot;áéíóúñü&quot;</p>
  <p>The result shoud be:</p>
  <p>&quot;c3a1c3a9c3adc3b3c3bac3b1c3bc&quot;</p>
  <p>I try following post, and others:</p>
  <p><a href="https://stackoverflow.com/questions/3381614/c-convert-string-to-hexadecimal-and-vice-versa">C++ convert string to hexadecimal and vice versa</a></p>
  <p><a href="https://stackoverflow.com/questions/12406084/how-to-convert-a-string-in-hexadecimal-string?lq=1">How to convert a string in hexadecimal string?</a></p>
  <p><a href="http://www.cplusplus.com/forum/beginner/161703/" rel="nofollow noreferrer">http://www.cplusplus.com/forum/beginner/161703/</a></p>
  <hr />
  <p>I will try to explain better, but I can not speak English properly. Sorry.</p>
  <p>I have to send some data using socket. For that I have to convert names to hexadecimal using UTF-8, but in some cases have specials characters for example á, é, í...
  When converting normal letters get a string length of 2 per letter.</p>
  <blockquote>
  <p>a-&gt; &quot;61&quot;</p>
  <p>e-&gt; &quot;65&quot;</p>
  </blockquote>
  <p>But special characters are encoded (on UTF-8) with length 4</p>
  <blockquote>
  <p>á-&gt; &quot;c3a1&quot;  this is the correct conversion</p>
  <p>é-&gt; &quot;c3a9&quot;  this is the correct conversion</p>
  </blockquote>
  <p>I have attempted the conversion of all the ways I've found, including that suggested me down. But every time you convert a special character gives me an answer of 2 digits, that is not correct.</p>
  <blockquote>
  <p>á-&gt; &quot;e1&quot;  this isnt correct</p>
  <p>é-&gt; &quot;e9&quot;  this isnt correct</p>
  </blockquote>