开发者

How to parse a binary file using Javascript and Ajax

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.

Any hints as to why the last value is incorrect?


A similar question was answered here. The short answer is that you can't easily handle binary data in javascript, and charCodeAt deals with Unicode characters so it's certainly not suitable for binary manipulation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜