title: c++ function to convert hexadecimal string to uint8_t array
body: <p>What is a simple way to write a function that coverts a c++ std::string which is in hexadecimal format into a uint8_t array?</p>
  <p>For example:</p>
  <pre><code>#include &lt;cstdint.h&gt; //for uint8_t
  #include &lt;cstring.h&gt; //for size_t
  
  
  uint8_t output[64];
  std::string input(&quot;EC83515650243FC512269A59CE0A82F4D4C92CD09F6037026BAA1A56AA97EBCB&quot;);
  int ret = 0;
  
  
  ret = hexStrToByteArray(input, output, sizeof(output));
  </code></pre>
  <p>Bonus points if you use C++17.</p>
  <p>I think the function hexStrToByteArray can be something like:</p>
  <pre><code>int hexStrToByteArray(std::string input, uint8_t * output, size_t outLen)
  {
    if(input.length()/2 != outLen)
    {
      return -1;
    }
  
    //TODO convert input into output
  }
  </code></pre>
  <p>This seems like it should have already been answered on stack overflow, but I could only find answers that did the conversation in a c-like style or where the output was a vector instead of an array.</p>