title: How to save hex value from string in uint8_t or char without converting the value?
body: <p>I have a binary file which I am reading and saving as hex values. These hex values will be used to flash a device, but I need the hex values to be stored as either uint8_t or char (preferably uint8_t). Currently the values are stored in a string, and only one byte at a time. What I want to do is to store the value as uint8_t instead of string.</p>
  
  <p>So if the value of <code>std:string result</code> is <code>0x3A</code>, I want the value of <code>uint8_t flash[1]</code> to be <code>0x3A</code>, and not <code>58</code> or some other value.</p>
  
  <p>How can this be achieved?</p>
  
  <p>Any help is appreciated :)</p>
  
  <p>EDIT:</p>
  
  <p>As I first expected, and has been confirmed, the values are the same whichever method I am using.
  For those who wish to see the code generating the string, here it is:</p>
  
  <pre><code>unsigned char x;
  std::ifstream input(file, std::ios::binary);
  input &gt;&gt; std::noskipws;
  
  std::stringstream stream, str;
  stream &lt;&lt; std::hex &lt;&lt; std::setw(2) &lt;&lt; std::setfill('0') &lt;&lt; (int)x;
  std::string result( stream.str() );
  
  str &lt;&lt; result;
  int value;
  str &gt;&gt; std::hex &gt;&gt; value;
  uint8_t data = value;
  </code></pre>