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

前端 未结 5 2068
心在旅途
心在旅途 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:16

    ~x will reverse the bit representation of your x value (32 bits signed value with two's complement).

    x << y is the left shift operator (here left). Your mathematical interpretation is correct :)

    You can read more about bitwise operations over here: bitwise operators in Javascript

提交回复
热议问题