Description
Performs a sign-propagating right bit shift operation, moving all bits to the right by the specified number of positions. The sign bit is copied to fill the leftmost positions.Syntax
Parameters
Returns
Type: number (integer) The result of shifting the bits right by the specified positions, with sign extension.Examples
Example 1: Basic Right Shift
Example 2: Divide by Power of Two
Example 3: Sign Extension with Negative Numbers
Example 4: Extracting Higher Bits
Notes
- Operates on 32-bit signed integers in JavaScript
- Uses arithmetic (sign-propagating) right shift
- Right shift by n is equivalent to integer division by 2^n (truncated toward negative infinity)
- Sign bit is copied to fill vacated positions (sign extension)
- Bits shifted off the right are discarded
- Useful for division by powers of 2 and extracting bit fields
See Also
- bitwise.shiftLeft - Shift bits to the left
- bitwise.and - Bitwise AND operation
- bitwise.or - Bitwise OR operation
Frequently Asked Questions
What does flex.bitwise.shiftRight do?
What does flex.bitwise.shiftRight do?
It shifts all bits in an integer to the right by the specified number of positions with sign extension — the sign bit is preserved for negative numbers.
Does shiftRight perform arithmetic or logical shift?
Does shiftRight perform arithmetic or logical shift?
It performs an arithmetic right shift (sign-extending). Negative numbers remain negative after shifting. Each right shift effectively divides the value by 2 (rounding toward negative infinity).