How to parse a binary file using Javascript and Ajax
- by Alex Jeffery
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?