PLC Shift Register SHL/SHR: 4 Essential Real Applications

Share:
DCS & Automation
PLC Shift Register: SHL and SHR

A 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.

SHL / SHR Register Calculator Shift vs Rotate Conveyor Tracking Example

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.

PLC Shift Register

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.

Advertisement
Advertisement

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.

SHL Moves Bits Toward the High End 0 1 0 1 discarded SHR Moves Bits Toward the Low End Fill 1 0 1
SHL discards a bit off the high end and fills a zero (or a chosen fill bit) in at the low end. SHR does the mirror operation in the other direction.

Shift vs Rotate: Why the Fill Bit Matters

InstructionDirectionVacated Bit Filled WithBit Falling Off the Edge
SHLToward MSBChosen fill bit, usually 0Discarded permanently
SHRToward LSBChosen fill bit, or sign bit on signed shiftsDiscarded permanently
ROL / ROREither directionThe bit that just fell off the opposite endNever 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.

Advertisement
Advertisement

SHL / SHR Register Calculator

Enter a starting value, register width, direction, number of positions, and fill bit to see the exact resulting bit pattern.

🔌
SHL / SHR Register Calculator
Runs a real bit shift step by step
-
-

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.

Start = 00000101 (5)
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.

Start = 10100000 (160)
SHR by 3, fill bit 1

Result = 11110100 (244)
Advertisement
Advertisement

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

DOC
How to Use the Shift and Rotate Instructions in PLC
instrumentationtools.com
DOC
Shift Register in PLC: Sorting Machine Example
automationcommunity.com
Advertisement
Advertisement

PLC Shift Register Questions Engineers Ask

What happens to a bit that shifts off the end of the register?
On a plain SHL or SHR instruction, that bit is discarded permanently. If the application needs to keep every bit, a rotate instruction, ROL or ROR, should be used instead, since it wraps the outgoing bit back around to the opposite end.
What fills the empty bit position after a shift?
Usually a fixed fill bit, most often zero on a logical shift. Some platforms let a signed arithmetic shift right fill with the sign bit instead, keeping a negative value negative after the shift.
How is a shift register used to track parts on a conveyor?
A sensor sets a bit representing a detected part. A timed pulse tied to the conveyor's movement shifts that bit one position with every step, so the bit's current position always corresponds to the part's real physical location downstream.
Is a shift register the same thing as a hardware shift register chip?
Conceptually yes, both move bits one position per clock or scan. A PLC shift register is implemented in software as part of the program's logic, while a hardware shift register chip is a physical flip flop based circuit.
Should shifting happen every scan or only on a specific event?
Almost always only on a specific event, detected with edge triggered logic. Shifting every scan, dozens or hundreds of times a second, would move the register far faster than the real world process it is meant to represent.
What is the difference between SHL/SHR and the BSL/BSR bit shift instructions?
SHL and SHR typically shift an entire integer or word value. BSL and BSR, common on Allen Bradley platforms, shift an entire array of bits and allow a separate source bit input to control exactly what value enters the vacated position.

External References

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.
"A shift register never creates a new bit. It only ever moves one, and quietly loses whatever falls off the edge."

Leave a Reply

Your email address will not be published. Required fields are marked *