title: Converting hex string 2 chars at a time
body: <p>I'm reading through some JavaScript code that parses a hex string into a buffer, like so:</p>
  
  <pre><code>function bufferFromHexString(string)
  {
      var buffer = new Buffer(string.length/2);
  
      for (var i=0; i&lt;string.length/2; i++)
      {
          buffer.writeInt8( parseInt(input.substr(i*2,2), 16), i );
      }
  
      return buffer;
  }
  </code></pre>
  
  <p>But I'm not sure why this is taking two characters at a time, rather than one. Can anyone explain  this?</p>