Reputation: 8769
I can use Uint8Array
for 8 bits, Uint32Array
for 32 bits, but I can't find an alternative which allows me to use 128 bits. Is there a computationally and memory efficient way to store such values?
At the moment I'm just approximating it by using an Array
, but that appears to be ~5x slower than a Uint32Array
.
Upvotes: 0
Views: 1151
Reputation: 8876
Typed arrays only go as large as Float64Array
. If you need uint
s, the largest you can get is UInt32Array
. If you need 128 bits, you'll need to create logic which can place your bits into a UInt32Array
as 4 DWORDs.
Also keep in mind that JavaScript Bitwise Operators only operate at 32-bit, so even if you try to shift the DWORDs of your values to re-assemble your 128-bit number, it will likely truncate your data into nothing.
Upvotes: 2