Table of Contents
ToggleA shift register moves every bit in a value one position over, letting a bit act like a token traveling down a virtual conveyor line inside the PLC.
SHL pushes bits toward the high end. SHR pushes them toward the low end. Whatever bit falls off the far side is gone unless something is rotating it back around.
This single operation quietly tracks parts on real conveyors, drives sequential lighting, and packs individual status bits into one compact word.
This guide covers how SHL and SHR actually move bits, what fills the gap left behind, and a calculator that runs a real shift step by step.
A PLC shift register uses the SHL, shift left, and SHR, shift right, instructions to move every bit in a value one position at a time, with SHL moving bits toward the most significant bit and SHR moving them toward the least significant bit, filling the vacated position with a chosen bit and discarding whatever bit falls off the far end.
A shift register looks like a small operation, moving bits one position, but that single motion is the backbone of a lot of practical PLC logic.
SHL and SHR are the two directions that motion can go, and the rules for what enters the empty spot and what falls off the edge decide how the register actually behaves.

This article breaks down both instructions, works through real shift calculations, and covers where a shift register earns its keep on a real machine.
How SHL, Shift Left, Actually Works
SHL moves every bit in a register one position toward the most significant bit, the highest numbered bit position.
The least significant bit position, left empty by the shift, gets filled with a chosen fill bit, usually zero on a standard logical shift.
Whatever bit sat in the most significant position before the shift is discarded entirely, gone unless a rotate instruction is used instead of a plain shift.
How SHR, Shift Right, Actually Works
SHR moves every bit one position toward the least significant bit, the mirror direction of SHL.
The most significant bit position, left empty by the shift, gets filled with the chosen fill bit. On a signed value, some platforms fill that position with the original sign bit instead of a plain zero, preserving whether the value reads as positive or negative.
Whatever bit sat in the least significant position before the shift is discarded, exactly the same loss SHL causes on the opposite end.
Shift vs Rotate: Why the Fill Bit Matters
| Instruction | Direction | Vacated Bit Filled With | Bit Falling Off the Edge |
|---|---|---|---|
| SHL | Toward MSB | Chosen fill bit, usually 0 | Discarded permanently |
| SHR | Toward LSB | Chosen fill bit, or sign bit on signed shifts | Discarded permanently |
| ROL / ROR | Either direction | The bit that just fell off the opposite end | Never lost, enters again on the register |
A plain shift always loses one bit of information per step. A rotate instruction never loses anything, since the bit falling off one end wraps directly back around to fill the gap on the other end.
SHL / SHR Register Calculator
Enter a starting value, register width, direction, number of positions, and fill bit to see the exact resulting bit pattern.
Two Shifts Worked Through
Starting value 5, binary 00000101, shifted left by 2 positions with a zero fill bit lands on 20, binary 00010100, the two low bits filled with zero and the top two original bits pushed off.
SHL by 2, fill bit 0
Result = 00010100 (20)
Starting value 160, binary 10100000, shifted right by 3 positions with a one fill bit lands on 244, binary 11110100, the top three bits filled with ones instead of the usual zero.
SHR by 3, fill bit 1
Result = 11110100 (244)
Four Real Shift Register Applications
Conveyor Part Tracking
A bit set at a scan point shifts one position with every conveyor pulse, tracking the part's position downstream in real time.
Sequential Lighting Effects
A single active bit shifted repeatedly through a register lights one output at a time, producing a chasing light pattern.
Bit Level Data Packing
Several individual status bits get packed into one word using repeated shifts, saving memory over separate boolean tags.
Circular Buffer via Rotate
A rotate instruction keeps a fixed set of bits cycling indefinitely, useful for round robin selection logic.
PLC Shift Register Do's and Don'ts
✓ Do
- Decide up front whether lost bits actually matter, use rotate instead of shift if they do
- Match the register width to the actual data being tracked, oversized registers waste memory
- Time each shift pulse to the real world event it represents, like a conveyor index signal
- Check whether a platform's shift instruction preserves the sign bit before using it on signed values
✗ Don't
- Assume a shifted out bit is recoverable, a plain SHL or SHR discards it permanently
- Confuse a logical shift with an arithmetic shift when signed numbers are involved
- Shift on every scan when the intent is one shift per real world event, add edge detection first
- Forget to initialize the register before first use, a stale value shifts along with everything else
Resources on PLC Shift Registers
PLC Shift Register Questions Engineers Ask
Related Articles
External References
- Instrumentation Tools: How to Use the Shift and Rotate Instructions in PLC
- Automation Community: Shift Register in PLC, Sorting Machine Example
What We Learn Today
- SHL shifts bits toward the high end and SHR shifts them toward the low end, each discarding one bit per position shifted.
- The vacated bit position is filled by a chosen fill bit, and a rotate instruction avoids losing data by wrapping the outgoing bit back around.
- Shift registers commonly track parts on conveyors, drive sequential lighting, and pack multiple status bits into one word.
- Shifting should be tied to a real world event with edge triggered logic, not run on every scan.
