What does 'x << ~y' represent in JavaScript?

前端 未结 5 2035
心在旅途
心在旅途 2020-12-24 02:08

What does \'x << ~y\' represent in JavaScript?

I understand that the bitwise SHIFT operation does this:

x << y AS x * 2y         


        
5条回答
  •  生来不讨喜
    2020-12-24 02:24

    5 << ~3 gives the same result as 5 << -4, you are right.

    Important thing: shifting x << y really results into x * 2y, but it is not a direct usage, it is just a useful side-effect.
    Moreover, if you have a negative y, it doesn't work in the same way.

提交回复
热议问题