title: Converting a hex string to a byte array
body: <p>What is the best way to convert a variable length hex string e.g. <code>"01A1"</code> to a byte array containing that data.</p>
  
  <p>i.e converting this:</p>
  
  <pre><code>std::string = "01A1";
  </code></pre>
  
  <p>into this</p>
  
  <pre><code>char* hexArray;
  int hexLength;
  </code></pre>
  
  <p>or this</p>
  
  <pre><code>std::vector&lt;char&gt; hexArray;
  </code></pre>
  
  <p>so that when I write this to a file and <code>hexdump -C</code> it I get the binary data containing <code>01A1</code>.</p>