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
Free · no signup to try
Run this block in your browser
Try the instruction on a live rung before you copy it into a project — nothing to install.
Try it in your browser — no signupOpens plcsimulationsoftware.com — same team
Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad
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 →Free · no signup to try
Wire this block up and run it
Drop the instruction into a rung, press Run and watch it execute in your browser — then adapt it to your vendor tool.
Try it in your browser — no signupOpens plcsimulationsoftware.com — same team
Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad