Most commanly, the modulo % operator is used to check for an even or odd number.
Now I have a question: is there any problems with an odd number using bitwise AND, since it feels a lot more natural, checking if the rightmost bit is 1 or 0 than doing a unit check against 2
And since the 32-bit conversion does not change the rightmost bit.
AND
(1 + Math.pow(2,52)) & 1 //1
and
(1 + Math.pow(2,52)) % 2 //1
give the same result.
Is there a reason to prefer the modulo operator over bitwise?
Edit: This question only takes into account values ββthat are in the 64-bit precision range since only even numbers can be represented as accurate above 2 ^ 53, and therefore both operands fail ( 9007199254740993 % 2 //0)
javascript modulo bitwise-and
C5H8NNaO4
source share