title: How to convert a hex string to a byte and a byte to a hex string in Javascript?
body: <p>How do you convert a hex code represented in a string to a byte and the reverse in Javascript?</p>
  
  <pre><code>var conv = require('binstring');
  var hexstring ='80';
  var bytestring = conv(hexstring, {in:'hex', out:'utf8'});
  var backtohexstring = conv(bytestring, {in:'utf8', out:'hex'}); // != '80'???
  </code></pre>
  
  <p>backtohexstring decodes an incoming data string to the correct hex (I also used utf8 vs. byte, because it 'looked' like the incoming string when printed to the console), so I'm confused...</p>
  
  <p>I also found these two native javascript functions, the decoder works on my incoming stream, but I still can't get the hex to encode...</p>
  
  <pre><code>function encode_utf8( s ) {
    return unescape( encodeURIComponent( s ) );
  }
  function decode_utf8( s ) {
    return decodeURIComponent( escape( s ) );
  }
  </code></pre>