title: A story of stringstream, hexadecimal and characters
body: <p>I have a string containing hexadecimal values (two characters representing a byte). I would like to use <code>std::stringstream</code> to make the conversion as painless as possible, so I came up with the following code:</p>
  
  <pre><code>std::string a_hex_number = "e3";
  
  {
      unsigned char x;
      std::stringstream ss;
      ss &lt;&lt; std::hex &lt;&lt; a_hex_number;
      ss &gt;&gt; x;
      std::cout &lt;&lt; x &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>To my biggest surprise this prints out <code>"e"</code> ... Of course I don't give up so easily, and I modify the code to be:</p>
  
  <pre><code>{
      unsigned short y;
      std::stringstream ss;
      ss &lt;&lt; std::hex &lt;&lt; a_hex_number;
      ss &gt;&gt; y;
      std::cout &lt;&lt; y &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>This, as expected, prints out <code>227</code> ...</p>
  
  <p>I looked at <a href="http://www.cplusplus.com/reference/istream/istream/operator%3E%3E/" rel="nofollow">http://www.cplusplus.com/reference/istream/istream/operator%3E%3E/</a> and <a href="http://www.cplusplus.com/reference/ios/hex/" rel="nofollow">http://www.cplusplus.com/reference/ios/hex/</a> but I just could not find a reference which tells me more about why this behaviour comes ...(yes, I feel that it is right because when extracting a character it should take one character, but I am a little bit confused that <code>std:hex</code> is ignored for <code>char</code>acters). Is there a mention about this situation somewhere?</p>
  
  <p>(<a href="http://ideone.com/YHt7Fz" rel="nofollow">http://ideone.com/YHt7Fz</a>)</p>
  
  <p><strong>Edit</strong> I am specifically interested if this behaviour is mentioned in any of the STL standards. </p>