![]() ![]() ![]() | |
![]() | |
![]() | |
![]() |
Flash Player 5.
expression1
>>expression2
expression1
A number or expression to be shifted right.
expression2
A number or expression that converts to an integer from 0 to 31.
Nothing.
Operator (bitwise); converts expression1
and expression2
to 32-bit integers, and shifts all of the bits in expression1
to the right by the number of places specified by the integer resulting from the conversion of expression2
. Bits that are shifted to the right are discarded. To preserve the sign of the original expression
, the bits on the left are filled in with 0 if the most significant bit (the bit farthest to the left) of expression1
is 0, and filled in with 1 if the most significant bit is 1. Shifting a value right by one position is the equivalent of dividing by 2 and discarding the remainder.
The following example converts 65535 to a 32-bit integer, and shifts it 8 bits to the right.
x = 65535 >> 8
The result of the above operation is as follows:
x = 255
This is because 65535 decimal equals 1111111111111111 binary (sixteen 1's), 1111111111111111 binary shifted right by 8 bits is 11111111 binary, and 11111111 binary is 255 decimal. The most significant bit is 0 because the integers are 32-bit, so the fill bit is 0.
The following example converts -1 to a 32-bit integer and shifts it 1 bit to the right.
x = -1 >> 1
The result of the above operation is as follows:
x = -1
This is because -1 decimal equals 11111111111111111111111111111111 binary (thirty-two 1's), shifting right by one bit causes the least significant (bit farthest to the right) to be discarded and the most significant bit to be filled in with 1. The result is 11111111111111111111111111111111 (thirty-two 1's) binary, which represents the 32-bit integer -1.
>>= (bitwise right shift and assignment)
![]() | |
![]() | |
![]() | |
![]() ![]() ![]() |