3 ms·
I'd be skeptical of the performance of any getBits() implementation. With the traditional approach ((X >> A) & B), you'll have to redundantly bit-shift all the
by LegionMammal978 1y ago
I'd be skeptical of the performance of any getBits() implementation. With the traditional approach ((X >> A) & B), you'll have to redundantly bit-shift all the data above the field you're aiming for. The other option would be to mask prior to the shift, but then you have a redundant copy of the data below the field.
Also, there's no great story for getting a large byte blob into or out of a BigInt, short of converting it all to ASCII hex and back. I ran into that limitation when attempting to use BigInts for arbitrary-precision arithmetic.
For simple data storage, I'd rather just use a Uint32Array and split/merge bits over element boundaries as appropriate.