What does 'x << ~y' represent in JavaScript?
I understand that the bitwise SHIFT
operation does this:
x << y AS x * 2y
And a tilde ~
operator does:
~x AS -(x+1)
So, I assume the following:
5 << ~3 AS 5 * 2-4 or 5 * Math.pow(2, -4)
It should result in 0.3125
.
But, when I run 5 << ~3
it results in 1342177280
.
What is a step-by-step explanation? How and why does this combination of operations result in 1342177280
instead of 0.3125
?
(This question is similar to Stack Overflow question What are bitwise operators? about the bitwise SHIFT
operator.)