Reputation: 5444
I want to write out to, and read in ieee format float/double values from a binary byte stream in a javascript module. Anyone know of how one would go about doing this? an equivalent to the doubleToRawLongBits and longBitsToDouble functionality in java.
Upvotes: 2
Views: 143
Reputation: 664484
You'll want to use a typed array for such things. Store your doubles into a Float64Array
, then access the raw bytes from the underlying ArrayBuffer
(and use bit shifts on those if you need single bits). If you're doing something more complicated, want to mix multiple types, or even control the endianness, overlay it with a DataView
.
Upvotes: 5