ShiftRight
Shift the integer value in register P2 to the right by the number of bits specified by the integer in register P1.
An example
1 of the 178 statements we compiled against the sample database use ShiftRight. This is the one with the shortest program; the rows that use ShiftRight are highlighted.
SELECT id & 1, id | 2, id << 3, id >> 1, ~id FROM tracks
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 16 | 0 | 0 | |
| 1 | OpenRead | 1 | 19 | 0 | k(2,,) | 0 |
| 2 | Rewind | 1 | 15 | 1 | 0 | 0 |
| 3 | IdxRowid | 1 | 6 | 0 | 0 | |
| 4 | BitAnd | 7 | 6 | 1 | 0 | |
| 5 | IdxRowid | 1 | 6 | 0 | 0 | |
| 6 | BitOr | 8 | 6 | 2 | 0 | |
| 7 | IdxRowid | 1 | 6 | 0 | 0 | |
| 8 | ShiftLeft | 9 | 6 | 3 | 0 | |
| 9 | IdxRowid | 1 | 6 | 0 | 0 | |
| 10 | ShiftRight | 7 | 6 | 4 | 0 | |
| 11 | IdxRowid | 1 | 6 | 0 | 0 | |
| 12 | BitNot | 6 | 5 | 0 | 0 | |
| 13 | ResultRow | 1 | 5 | 0 | 0 | |
| 14 | Next | 1 | 3 | 0 | 1 | |
| 15 | Halt | 0 | 0 | 0 | 0 | |
| 16 | Transaction | 0 | 0 | 1 | 0 | 1 |
| 17 | Integer | 1 | 7 | 0 | 0 | |
| 18 | Integer | 2 | 8 | 0 | 0 | |
| 19 | Integer | 3 | 9 | 0 | 0 | |
| 20 | Goto | 0 | 1 | 0 | 0 |
Open it in the EXPLAIN visualizer →
Also in this program: BitAnd, BitNot, BitOr, Goto, Halt, IdxRowid, Init, Integer, Next, OpenRead, ResultRow, Rewind, ShiftLeft, Transaction.
What the SQLite documentation says
Shift the integer value in register P2 to the right by the number of bits specified by the integer in register P1. Store the result in register P3. If either input is NULL, the result is NULL.
From sqlite.org's list of opcodes for SQLite 3.54.1, in the public domain. Opcodes are not a stable interface and change between releases.