title: Convert a string variable of two chars to hex
body: <p>I have code where the user inputs two chars into a <code>string</code> variable. I have a function that verifies that the user input is only two chars long, and that it only contains valid hexadecimal digits.</p>
  
  <p>I want to write these digits to a binary file that's 32 bytes long. I tried:</p>
  
  <pre><code>    outFile.write((char*)&amp;string[0], 1);
  </code></pre>
  
  <p>In a loop that runs 32 times (I want to write one byte at a time) to test, but it just writes the ascii code for the char, not the actual char itself. I expected it to write a nybble and skip a nybble, but it wrote a full byte of ascii information instead. So I tried:</p>
  
  <pre><code>    outFile.write((unsigned char*)&amp;string[0], 1);
  </code></pre>
  
  <p>But my compiler complains about it being an invalid cast. </p>
  
  <p>I want to solve this problem without converting the string into a c-style string. In other words, I want <code>string</code> to contain two chars and represent one byte of information. Not four (plus null characters).</p>