# CODESYS SHR

Instructions · `SHR` · verification: source checked

SHR is an IEC bitwise shift operator that moves the bits of an operand to the right by a given number of places. It is written as erg := SHR (in, n), where in is the operand being shifted and n is the number of bit positions to shift. The result is assigned to the output variable erg, as shown in the structured text example where 16#45 shifted right by 2 gives 16#11.

## Specification

| Property | Value |
|---|---|
| Language | structured text |
| Code | SHR |
| Group | bitwise shift |
| Syntax | erg := SHR (in, n) |
| Dialect | CODESYS |

### Parameters

| Name | Description |
|---|---|
| in | Operand which is shifted to the right |
| n | Number of bits to shift in to the right |

## Study notes

- SHR operates on bit strings; the example shifts a BYTE (16#45, 2#01000101) and a WORD (16#0045, 2#0000000001000101).
- With n = 2, SHR(in_byte, n) returns 16#11 (2#00010001) and SHR(in_word, n) returns 16#0011 (2#0000000000010001).
- If n exceeds the data type width, how BYTE, WORD, DWORD and LWORD operands are padded depends on the target system: padding is either with zeros or by n MOD <register size>.
- The operator is demonstrated in a structured text (ST) program and also shown in FBD form.

## Sources

1. [Beckhoff Information System](https://infosys.beckhoff.com/content/1033/tc3_plc_intro/2528939915.html) (accessed 2026-10-26)
2. [CODESYS Group](https://content.helpme-codesys.com/en/CODESYS%20Development%20System/_cds_operator_shr.html) (accessed 2026-10-26)

---

Source page: https://machineschema.com/instruction/iec-shr  
JSON: https://machineschema.com/instruction/iec-shr.json  
License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Cite Machine Schema and the original sources.
