title: Hex character to int in C++
body: <p>How can I change a hex character, not string, into a numerical value? </p>
  
  <p>While typing this question, I found many answers on how to convert hex strings to values. However, none work for chars. I remember reading somewhere that this works for strings:</p>
  
  <pre><code>std::string mystr = "12345";
  unsigned int myval;
  std::stringstream(mystr) &gt;&gt; std::hex &gt;&gt; myval;
  </code></pre>
  
  <p>However, if I do <code>mystr[x]</code> in a loop, this code will not work. I have tried adding a new line with <code>std::string temp = mystr[x]</code> and changing <code>std::stringstream(mystr)</code> to <code>std::stringstream(temp)</code>, but that's not working either. </p>
  
  <p>So how should I do this? Currently, I'm searching through a string of the hex chars (<code>"0123456789abcdef".find(mystr[x]);</code>) and using the index for the value. However, since it searches, it's slow, even if it's only searching through 16 characters.</p>
  
  <p><a href="http://ideone.com/dIyD4" rel="noreferrer">http://ideone.com/dIyD4</a></p>