Skip to main content

$bitRightShift

The $bitRightShift operator performs a bitwise right shift operation on the first integer by the second integer number of positions.

Input

  • An array containing exactly two integer values: the value to shift and the number of positions to shift

Output

  • The result of shifting the first value right by the specified number of positions

Examples

Basic Right Shift

{
  "$bitRightShift": [
    10,
    1
  ]
}
Result: 5 (binary: 1010 “right shift” 1 = 0101)

Multiple Position Shift

{
  "$bitRightShift": [
    12,
    2
  ]
}
Result: 3 (binary: 1100 “right shift” 2 = 0011)

Field Value

{
  "$bitRightShift": [
    {
      "$input": "value"
    },
    {
      "$input": "positions"
    }
  ]
}
Result: The value field right-shifted by the positions field