PLC Bit Shift and Rotate Instructions: BSL, BSR, ROL, ROR Explained

Share:
DCS and Automation
PLC Bit Shift and Rotate Instructions: BSL, BSR, ROL, ROR Explained

Bit shift and rotate instructions move bits through a register or array one position at a time. BSL and BSR shift through arrays. ROL and ROR rotate within a single register.

BSL Bit Shift Left BSR Bit Shift Right ROL Rotate Left ROR Rotate Right Ladder Logic
Hello everyone, today we are going to learn about PLC bit shift and rotate instructions: BSL, BSR, ROL, and ROR.

We will understand how each instruction moves bits through registers or arrays, what happens to the bit that falls off the end, and what value enters from the other end.
We will also cover the key differences between shift and rotate instructions, look at bit-state tables for each instruction, and see real application examples in PLC ladder logic programs.

Bit shift and rotate instructions are used in conveyor tracking, step sequencers, and pattern generators where a bit must move through a series of positions in a controlled way.

PLC bit shift

PLC Bit Shift and Rotate Instructions: BSL BSR ROL ROR Overview

BSL (Bit Shift Left)
Array → shifts toward higher bit

Shifts all bits in an array toward the high end. A new bit enters at bit 0 from Source. The exiting bit goes to the UL overflow bit.

BSR (Bit Shift Right)
Array → shifts toward lower bit

Shifts all bits in an array toward the low end. A new bit enters at the top from the Source parameter. The exiting bit goes to the UL overflow bit.

ROL (Rotate Left)
Register → wraps bit back to bit 0

Rotates all bits in a single register one position to the left. The bit exiting the top wraps back to bit 0. No bit is lost. The register content circulates continuously.

ROR (Rotate Right)
Register → wraps bit back to top

Rotates all bits in a single register one position to the right. The bit that shifts out of bit 0 wraps back and re-enters at the top bit. No bit is lost.

Advertisement

BSL: Bit Shift Left Instruction

BSL operates on a bit array. Each rising edge shifts every bit one position left. A new bit enters at bit 0 from Source. The exiting bit goes to the UL bit.

BSL Instruction Parameters
BSL
  File:   Conveyor_Bits[0]  ( DINT array, starting element )
  Source: New_Part_Sensor   ( bit to enter at position 0 on each shift )
  Control: R6:0          ( control structure: .UL = overflow bit )
  Length: 16             ( total bits to use in the array )
StateBit 0Bit 1Bit 2Bit 3UL (overflow)
Before shift10110
Source bit = 0
After BSL01011

The original bit 3 (value 1) moved into the overflow (UL) bit. Source bit value 0 entered at bit 0. Every other bit moved one step to the left.

Executes on
Rising edge of rung only. Each false-to-true transition shifts by one position.
New bit source
The Source parameter. Typically wired to a sensor, pushbutton, or another bit tag.
Exiting bit
Captured in the control structure UL (unload) bit. Read it before the next shift to act on it.
Typical use
Conveyor part tracking. A part detected by a sensor enters as a 1 bit and shifts along as the conveyor moves.

BSR: Bit Shift Right Instruction

BSR mirrors BSL. Each rising edge shifts all bits toward lower bit numbers. A new bit enters at the highest position. The exiting bit 0 goes to the UL bit.

StateBit 3Bit 2Bit 1Bit 0UL (overflow)
Before shift10100
Source bit = 1
After BSR11010

Source bit value 1 entered at bit 3. Every other bit moved one step to the right. The original bit 0 (value 0) moved into the UL overflow bit.

Advertisement

ROL and ROR: Rotate Instructions

ROL and ROR operate on a single register, not an array. The bit exiting one end re-enters from the other. No bit is ever lost.

InstructionBit 3Bit 2Bit 1Bit 0What happened
Before rotate1000
After ROL0001Bit 3 wrapped to bit 0
After ROR0100Bit 0 would wrap to bit 3 (from original)
ROL vs BSL key difference: BSL shifts bits through an array and the exiting bit is captured in the UL overflow bit (it leaves the register permanently). ROL wraps the exiting bit back to the entry point, so the total number of 1 bits in the register never changes. Use ROL or ROR for circular sequencers. Use BSL or BSR for data that travels in one direction and exits the array.

BSL vs BSR vs ROL vs ROR: Full Comparison

FeatureBSLBSRROLROR
DirectionLeft (toward high bit)Right (toward low bit)Left (wraps)Right (wraps)
Operates onBit array (multi-word)Bit array (multi-word)Single registerSingle register
New bit sourceSource parameter (external bit)Source parameter (external bit)Exiting bit (wraps back)Exiting bit (wraps back)
Exiting bitCaptured in UL overflow bitCaptured in UL overflow bitRe-enters at bit 0Re-enters at top bit
Bits lost?Yes (exits to UL then gone)Yes (exits to UL then gone)NoNo
Executes onRising edge onlyRising edge onlyRising edge onlyRising edge only
Typical useConveyor tracking, FIFO sequencingConveyor tracking (reverse), LIFO sequencingCircular step sequencer, rotating lamp patternCircular step sequencer (reverse), rotating pattern

Real Applications of Bit Shift and Rotate in PLC Programs

Conveyor tracking
A sensor at the entry point sets the Source bit. BSL shifts the bit along one position each time the conveyor indexes. Each output along the line reads its corresponding bit position to know whether a part is present at that station.
Step sequencer
One bit is set in a ROL register at startup. Each machine cycle rotates the register one step. Each bit position activates a different output, producing a repeating sequence without a counter or compare instruction.
Rotating lamp pattern
ROL or ROR drives a bank of indicator lamps in a rotating chase pattern. One active bit rotates through 8 or 16 output bits, moving the illuminated lamp one step per timer pulse.
Data serialisation
BSL is used to shift a parallel word out bit by bit over a serial communication line, sending the most significant bit first with each clock pulse.
FIFO buffer tracking
A bit array tracks which positions in a physical buffer are occupied. BSL shifts the occupancy pattern as products move through, and the UL bit indicates when a product exits the end of the buffer.

Watch: PLC Bit Shift Instructions Explained

Advertisement

PLC Bit Shift and Rotate Questions Engineers Ask

What is the difference between BSL and ROL in PLC ladder logic?
BSL shifts bits through an array and the exiting bit is captured in the UL bit. ROL rotates within a single register and wraps the exiting bit back so nothing is lost.
What does the UL bit do in BSL and BSR instructions?
The UL bit captures the bit exiting the array on each shift. Read it before the next rising edge. It is overwritten by the next exiting bit on the following shift.
When should I use BSL instead of SHL in a PLC program?
Use BSL when shifting bits across multiple words with a new external bit entering each shift. Use SHL when shifting a single word register by a fixed number of positions.
Does ROL execute every scan or only on a rising edge?
ROL executes on the rising edge only, shifting one position each false-to-true transition. If the rung stays true, ROL does not keep rotating. Use a timer pulse to control rotation speed.
What is a practical use of BSL in conveyor tracking?
A part sensor sets the Source bit. Each time the conveyor indexes one station, BSL shifts the part presence bit one position along the array, tracking the part without additional logic.

Related Articles on This Site

External References

Advertisement

What We Learn Today

  • BSL shifts bits left through an array on each rising edge. A new bit enters at bit 0 from the Source parameter. The bit that exits the top is captured in the UL overflow bit. BSR does the same in the opposite direction. Both instructions operate across a multi-word array and the exiting bit is permanently lost after the next shift.
  • ROL rotates bits left within a single register. The bit that exits the top re-enters at bit 0, so no bit is ever lost. ROR does the same in the opposite direction. After enough rotations equal to the register width, the original pattern is restored.
  • Use BSL or BSR for conveyor part tracking, FIFO buffer management, and data serialisation where bits travel through an array and exit at the end. Use ROL or ROR for circular step sequencers and rotating output patterns where the same set of bits must circulate continuously.
I hope you like above blog. There is no cost associated in sharing the article in your social media. Thanks for reading!! Happy Learning!!

Leave a Reply

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