TIA Portal Instructions

Shift and Rotate
Bit Manipulation

Optimize your register processing. From ultra-fast mathematical calculation to complex communication protocol management, master bit movement.

Why shift or rotate bits?

Shift and rotate operations allow moving bits of a word to the left or right. In industry, they are used to extract precise information from a communication telegram, create shift registers for tracking parts on a conveyor, or perform multiplications/divisions by powers of 2 with extreme performance.

The major difference lies in the treatment of 'outgoing' bits: while Shift discards them and replaces them with zeros, Rotate feeds them back into the other side of the word, creating a continuous circular loop.

Shift

Linear movement with bit loss

SHL / SHR — Shift Left/Right

SHL

What it does

Moves bits to the left (SHL) or right (SHR) by a number of positions defined by the N input. Bits that exit the register are lost, and new incoming bits are set to 0.

When to use it

Fast multiplication by 2 (SHL), division by 2 (SHR), or isolating a specific byte in a 32-bit word.

Pro Tips

Shifting an integer by 1 bit to the left is equivalent to multiplying it by 2 without using the mathematical unit.

For signed types (Int, DInt), SHR often preserves the sign bit (arithmetic shift).

If N is greater than the word size (e.g., N=20 for a WORD), the result will be 0.

Rotate

Circular movement without loss

ROL / ROR — Rotate Left/Right

ROL

What it does

Rotates bits circularly. The bit that exits from one side (e.g., left for ROL) immediately enters from the other side (right). No data is lost.

When to use it

Creating rotating light patterns, simple data encryption, or managing circular buffers (FIFO).

Pro Tips

Ideal for alternating priorities in a group of pumps or motors.

Unlike shifting, a complete rotation (e.g., 16 bits for a WORD) returns the initial value.

Use ROL/ROR to reorder byte order (Endianness) in data exchanges.

Shift vs Rotate: The match

Understanding the impact on your data

PropertyShift (SHL/SHR)Rotate (ROL/ROR)
StructureLinearCircular
Outgoing bitsDiscarded (Lost)Reinjected at opposite side
Incoming bitsAlways 0Recycled outgoing bits
Math usageMultiplication / DivisionBit permutation
Real-world examplePart tracking (Conveyor)Bit pattern / Sequencer
RiskRegister emptyingNone (data preserved)

Frequently Asked Questions

Why use SHL instead of multiplying by 2?

The SHL instruction is executed much faster by the PLC processor than a MUL operation because it works directly on the register without going through the complex ALU.

How to create a shift register for a conveyor?

Use SHR at each encoder pulse. If a part is detected at the entrance, force bit 0 to 1. By shifting the word, you track the part's position bit by bit.

What is the impact of the data type (Byte, Word, DWord)?

The instruction adapts to the size. A ROR on a Byte will make bit 7 reappear at position 0 after 1 shift. On a Word, bit 15 will return to 0.

Can variables be shifted in SCL?

Yes, via SHL(IN:=var, N:=n) functions or by using standard bitwise operators if your TIA Portal version allows it.

Automate your binary manipulations

Need to isolate bits or create a complex sequencer? T-IA Connect generates your shift and rotate networks in one click.