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
Not in a browser, no. Not yet.
--
Jorge.
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[i];
a <<= 8;
a += stream[i+1];
-- pete
> Right, but also (considering the input stream as an array of bytes):
>
> var a = stream[i];
> a <<= 8;
> a += stream[i+1];
No idea, outside of my knowledge.
Rgds
Denis McMahon