Unfamiliar characters used in JavaScript encryption script

后端 未结 3 1978
既然无缘
既然无缘 2020-12-16 18:28

Here is an excerpt from a JS encryption script that I am studying.

function permutationGenerator(nNumElements) {
    this.nNumElements     = nNumElements;
           


        
3条回答
  •  甜味超标
    2020-12-16 19:30

    | = bitwise or

    1010
    0100
    ----
    1110
    

    & = bitwise and

    1011
    0110
    ----
    0010
    

    so it's the same as && and || just with the single bits

    << is left shift, so

    0110 << 2 shifts the numbers left by two positions, yielding 011000 another way to think of this is multiplication by two, so x<<1 == x*2, x<<2 == x*2*2 and so on, so it's x * Math.pow(2,n) for x<

    >> 
    

    is the opposite, so 0110 >> 2 ---> 0001 you can think of it as division by two, BUT with rounding down, so it equals

    Math.floor(x/Math.pow(2,n)) 
    

提交回复
热议问题