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
| Name | Type | Description |
|---|---|---|
| IN | ANY_BIT | Value to shift |
| N | INT | Number of bit positions to shift right |
Outputs
| Name | Type | Description |
|---|---|---|
| OUT | ANY_BIT | Shifted 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
Siemens (TIA Portal)
Use SHR instruction in TIA Portal.
Allen-Bradley (Studio 5000)
Use BSR (Bit Shift Right) for single-bit shifts, or SHR for word-level.
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.
Related Function Blocks
SHL (Shift Left)
Shifts bits left by N positions, filling right with zeros. Equivalent to multiply by 2^N.
View Reference →ROL (Rotate Left)
Rotates bits left; bits shifted out the left wrap around to the right.
View Reference →MOVE (Data Move)
Copies a value from source to destination for any data type.
View Reference →SWAP (Byte Swap)
Reverses byte order of a word value for endianness conversion.
View Reference →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.
Instant download - 30-day money-back guarantee - Use on unlimited projects