Unfamiliar characters used in JavaScript encryption script

后端 未结 3 1965
既然无缘
既然无缘 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:06

    Left shift 8 bits and bitwise OR with j.

    << is the left shift operator. Shifts the bits in the variable left the number of positions indicated.

    >> is the right shift operator. Shifts the bits in the variable right the number of position indicated.

    | is the bitwise OR operator. Performs a logical OR on each bit in the two operands.

    & is the bitwise AND operator. Performs a logical AND on each bit in the two operands.

    0 讨论(0)
  • 2020-12-16 19:09

    << is a bitwise left shift. >> is a bitwise right shift. | is a bitwise OR. & is a bitwise AND. Please see this reference for more information.

    0 讨论(0)
  • 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)) 
    
    0 讨论(0)
提交回复
热议问题