Shift direction and byte numbering must be stated explicitly.
LET’S PICTURE IT
Moving a row of boxes is different from choosing one box by its printed index.
SEE IT FOR YOURSELF
Watch a stack machine execute a tiny programStep 1 / 4
The program bytes are PUSH1 02, PUSH1 03, ADD, STOP. The program counter begins at byte zero.
The program bytes are PUSH1 02, PUSH1 03, ADD, STOP. The program counter begins at byte zero.PUSH1 reads its next byte as an immediate value and places two on the stack. The next instruction begins at byte two.The next PUSH1 places three above two. Stack order matters for operations that are not commutative.ADD consumes the top two values and pushes five. The next instruction is STOP at byte five; no storage write is implied by ADD.
Animated local teaching model. No wallet, RPC or live blockchain data. Some labels and hashes are abbreviated for readability.
Distinguish logical directions
SHL shifts bits left, discarding overflow beyond the word. SHR shifts right and fills high positions with zeros.
Recognize arithmetic right shift
SAR preserves the signed interpretation by filling high bits according to the sign. It differs from SHR for words with the high bit set.
Read BYTE indexing
BYTE index zero selects the most significant byte of the word. This indexing direction differs from lower-order byte offsets used in Solidity packed storage.
Handle large shifts and indices
Boundary cases have specified outcomes. Do not rely on host-language shift operators that silently reduce the shift amount to a smaller machine width.