can I make Javascript see binary data?

P

pete

Hi everybody --

A friend asks me this question. He is reading mixed ASCII and binary
data into his Javascript code. He needs to parse the received record.
Some of the binary data are:

1. 16-bit integers
2. 32-bit integers
3. 8-bit integers
4. 32-bit IEEE floats.

So I think the question is: can I persuade Javascript to understand
and handle 8 arbitrary data bits in an untyped 8-bit byte?

If so, then how?

Thanks!

-- pete
 
R

Ry Nohryb

Hi everybody --

A friend asks me this question. He is reading mixed ASCII and binary
data into his Javascript code. He needs to parse the received record.
Some of the binary data are:

  1. 16-bit integers
  2. 32-bit integers
  3. 8-bit integers
  4. 32-bit IEEE floats.

So I think the question is: can I persuade Javascript to understand
and handle 8 arbitrary data bits in an untyped 8-bit byte?

Not in a browser, no. Not yet.
 
D

Denis McMahon

Hi everybody --

A friend asks me this question. He is reading mixed ASCII and binary
data into his Javascript code. He needs to parse the received record.
Some of the binary data are:

1. 16-bit integers
2. 32-bit integers
3. 8-bit integers
4. 32-bit IEEE floats.

So I think the question is: can I persuade Javascript to understand
and handle 8 arbitrary data bits in an untyped 8-bit byte?

If so, then how?

bitwise or, bitwise and etc.

eg (assuming bit 0 is lsb):

if (x & 0x80 == 0x80) alert ("bit 7 is set");
if (x | 0x7f == 0x00) alert ("bit 7 is clear");

x = (x | 0x80); // set bit 7 of x
x = (x & 0x7f); // clear bit 7 of x

Rgds

Denis McMahon
 
P

pete

bitwise or, bitwise and etc.

eg (assuming bit 0 is lsb):

if (x & 0x80 == 0x80) alert ("bit 7 is set");
if (x | 0x7f == 0x00) alert ("bit 7 is clear");

x = (x | 0x80); // set bit 7 of x
x = (x & 0x7f); // clear bit 7 of x

Rgds

Denis McMahon

Right, but also (considering the input stream as an array of bytes):

var a = stream;
a <<= 8;
a += stream[i+1];

-- pete
 
D

Denis McMahon

Right, but also (considering the input stream as an array of bytes):

var a = stream;
a <<= 8;
a += stream[i+1];


No idea, outside of my knowledge.

Rgds

Denis McMahon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top