Let's say I want to create a bitmask in Javascript. I would toggle a bit on like this:
mask |= (1 << bit);
clear a bit like this:
mask &= ~(1 << bit);
and check if a bit is set like this:
(bit & mask) != 0
My question is, what is the safest amount of bits that this works on in Javascript? I have three main guesses:
- 32 bits, as bit operations may be undefined past 32 bits
- 53 bits, as
Number.MAX_SAFE_INTEGERis2^53 - 1 - 64 bits, as Javascript uses 64 bits for each number
Which one is correct? Or is it something else?