title: How to parse a binary file using Javascript and Ajax
body: <p>I am trying to use JQuery to pull a binary file from a webserver, parse it in Javascript and display the contents. I can get the file ok and parse some of the file correctly. How ever I am running into trouble with one byte not coming out as expected.</p>
  
  <p>I am parsing the file a byte at a time, it is correct until I get to the hex value B6 where I am getting FD instead of B6.</p>
  
  <p>Function to read a byte</p>
  
  <pre><code>data.charCodeAt(0) &amp; 0xff;
  </code></pre>
  
  <p>File As Hex:
  02 00 00 00 55 4C 04 00 B6 00 00 00</p>
  
  <p>The format I want to parse the file out into.</p>
  
  <ul>
  <li>short: 0002 </li>
  <li>short: 0000 </li>
  <li>string: UL</li>
  <li>short: 0004 </li>
  <li>long: 0000B6</li>
  </ul>
  
  <p>Any hints as to why the last value is incorrect?</p>