Learn PLCs free
Data Movement & Bit ShiftingIntermediateIEC 61131-3

SHR (Shift Right)

Shifts bits right by N positions. Equivalent to integer division by 2^N.

The SHR (Shift Right) function shifts the bits of the input value to the right by a specified number of positions. Vacated bit positions on the left are filled with zeros (for unsigned types) or the sign bit (for signed types). Each right shift by 1 is equivalent to integer division by 2. SHR is used for extracting specific bits, fast division by powers of 2, and decoding packed status words.

Parameters

Inputs

NameTypeDescription
INANY_BITValue to shift
NINTNumber of bit positions to shift right

Outputs

NameTypeDescription
OUTANY_BITShifted result

Ladder Logic Example

// Ladder Logic - SHR (Extract Byte)
//
// |----[SHR]----|
// | IN: Status_Word       |
// | N:  8                 |
// | OUT: High_Byte        |

Structured Text Example

High_Byte := SHR(Status_Word, 8);  // Extract upper byte

// Fast divide by 4:
Result := SHR(Value, 2);  // Value / 2^2 = Value / 4

20 Production-Ready Ladder Logic Templates

Stop writing the same rungs from scratch. Get copy-paste-ready templates for motor control, PID loops, safety interlocks, conveyors, and more.

Platform-Specific Implementation

S

Siemens (TIA Portal)

Use SHR instruction in TIA Portal.

AB

Allen-Bradley (Studio 5000)

Use BSR (Bit Shift Right) for single-bit shifts, or SHR for word-level.

C

CODESYS

Use SHR() function in ST.

Common Applications

  • Bit field extraction
  • Fast division by powers of 2
  • Status word decoding
  • Protocol data unpacking
  • Byte extraction from words

Frequently Asked Questions

What is SHR (Shift Right) in PLC programming?

Shifts bits right by N positions. Equivalent to integer division by 2^N. The SHR (Shift Right) function shifts the bits of the input value to the right by a specified number of positions. Vacated bit positions on the left are filled with zeros (for unsigned types) or the sign bit (for signed types).

What are common applications of SHR (Shift Right)?

SHR (Shift Right) is commonly used for: Bit field extraction, Fast division by powers of 2, Status word decoding, Protocol data unpacking, Byte extraction from words.

How do I use SHR (Shift Right) in different PLC platforms?

Siemens: Use SHR instruction in TIA Portal. Allen-Bradley: Use BSR (Bit Shift Right) for single-bit shifts, or SHR for word-level. CODESYS: Use SHR() function in ST.

Stop Writing Ladder Logic From Scratch

Get 20 production-ready ladder logic templates for $29 -- download instantly and use them on your next project today.

20
Ready-Made Templates
LD + ST
Both Languages Included
$29
One-Time Purchase
Get Instant Access -- $29

Instant download - 30-day money-back guarantee - Use on unlimited projects

Free PLC simulator

Wire this block up and run it

Drop the instruction into a rung, hit Run, and watch it execute in your browser. 12 guided lessons across 8 PLC dialects — free account, no credit card.

Practice PLCs free →