Operators > >> (bitwise right shift)

>> (bitwise right shift)

Syntax

expression1 >> expression2

Arguments

expression1 A number, string, or expression to be shifted right.

expression2 A number, string, or expression that converts to an integer from 0 to 31.

Description

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 off 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.

Player

Flash 5 or later.

Example

The following example converts 65535 to a 32-bit integer, and shifts it eight 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 eight 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 one 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.

See also

>>= (bitwise right shift and assignment)