title: How to Convert Hex String to Uint8
body: <p>I would like to know why I am getting the result of 0 when converting a hex string (0x1) to a uint8. </p>
  
  <p>I tried to use <code>boost::lexical_cast</code> but I get a <code>bad_lexical_cast</code> exception. Therefore, I decided to use a <code>stringstream</code> instead but I am getting the incorrect value.</p>
  
  <pre><code>...
  uint8_t temp;
  std::string address_extension = "0x1";
  std::cout &lt;&lt; "Before: " &lt;&lt; address_extension &lt;&lt; std::endl;
  StringToNumeric(address_extension, temp);
  std::cout &lt;&lt; "After: " &lt;&lt; temp &lt;&lt; std::endl;
  ...
  
  template &lt;typename T&gt;
  void StringToNumeric(const std::string&amp; source, T&amp; target)
  {
      //Check if source is hex
      if(IsHexNotation(source))
      {
         std::stringstream ss;
         //Put value in the stream
         ss &lt;&lt; std::hex &lt;&lt; source;
         //Stream the hex value into a target type
         ss &gt;&gt; target;
       }
  
   }
  </code></pre>
  
  <p>You can be assured that <code>IsHexNotation()</code> works correctly and does not change the source as it is declared:</p>
  
  <pre><code>bool IsHexNotation(const std::string&amp; source)
  </code></pre>
  
  <p>What is the correct way to convert a hex string to a uint8 (given that the hex string WILL fit into the datatype)? </p>