Shift Operators

Top  Previous  Next

Operators:  <<  >>  >>>

Syntax:

expression1 << expression2

bitwise shift left

expression1 >> expression2

bitwise shift right, sign fill

expression1 >>> expression2

bitwise shift right, zero fill

 

The shift operators shift expression1 the number bits specified by expression2. Both expressions are converted to Number first, if necessary, and then both are converted to internal integer format. Before shifting, expression2 is masked to the 5 least significant bits (bitwise AND with 0x1F), which reduces it to the range 0 - 31.

 

The >> operator copies the sign bit into the bit positions vacated by the shift, thus ensuring the result is always the same sign as expression1. The >>> operator fills vacated bits with zero.