Skip to main content

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

Output:
(Binary: 10100 >> 2 = 00101 = 5)

Example 2: Divide by Power of Two

Output:
(Right shift by n is equivalent to integer division by 2^n)

Example 3: Sign Extension with Negative Numbers

Output:
(Sign bit is preserved in right shift)

Example 4: Extracting Higher Bits

Output:
(Extracts upper 4 bits: 00001111 = 15)

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

Frequently Asked Questions

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