Skip to main content

$bitLeftShift

The $bitLeftShift operator performs a bitwise left 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 left by the specified number of positions

Examples

Basic Left Shift

{
  "$bitLeftShift": [
    5,
    1
  ]
}
Result: 10 (binary: 101 “left shift” 1 = 1010)

Multiple Position Shift

{
  "$bitLeftShift": [
    3,
    2
  ]
}
Result: 12 (binary: 011 “left shift” 2 = 1100)

Field Value

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