JavaScript >> Right shift Operator
The right shift operator (>>) moves the bits of an integer to the right, keeping the sign, which divides it by a power of two.
Description
The right shift operator >> shifts the bits of a 32-bit integer to the right, copying the sign bit into the left so negative numbers stay negative. Shifting by n divides by 2n, rounding down.
Because the sign bit is copied in from the left, >> is also called the sign-propagating or arithmetic right shift. For positive numbers, x >> 1 is the same as Math.floor(x / 2); for negative numbers it rounds towards negative infinity, so -7 >> 1 is -4.
It's used to extract parts of packed values, for example getting the red channel from a 24-bit colour with (color >> 16) & 255. Only the lowest five bits of the shift amount are used.
Properties
- Operator
>>- Category
- Bitwise
- Precedence
- 10 (1 is lowest, 18 is highest)
- Associativity
- left-to-right
Syntax
x >> yExample
Browser Support
The following information will show you the current browser support for the >> operator. Hover over a browser icon to see the version that first introduced support for this operator.
Desktop





Tablets & Mobile





