How to parse a binary file using Javascript and Ajax

Posted by Alex Jeffery on Stack Overflow See other posts from Stack Overflow or by Alex Jeffery
Published on 2009-12-17T03:57:29Z Indexed on 2010/03/19 10:01 UTC
Read the original article Hit count: 274

Filed under:
|

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.

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.

Function to read a byte

data.charCodeAt(0) & 0xff;

File As Hex: 02 00 00 00 55 4C 04 00 B6 00 00 00

The format I want to parse the file out into.

  • short: 0002
  • short: 0000
  • string: UL
  • short: 0004
  • long: 0000B6

Any hints as to why the last value is incorrect?

© Stack Overflow or respective owner

Related posts about AJAX

Related posts about binary