CODESYS SHR

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.

Source checked7/7 values · 2026-10-26

Specification

2 sources
Languagestructured text
CodeSHR
Groupbitwise shift
Syntaxerg := SHR (in, n)
DialectCODESYS

Parameters

NameDescription
inOperand which is shifted to the right
nNumber 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.
↑↓ navigate↵ openesc close