Here is an excerpt from a JS encryption script that I am studying.
function permutationGenerator(nNumElements) {
this.nNumElements = nNumElements;
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.
<< 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.
| = 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))