SHR

The IEC Operators and additional, norm-extending \ functions Bitwise righ-shift of an operand : erg:= SHL (in, n)

in gets shifted to the right by n bits. If n > data type width, for BYTE, WORD and DWORD will be filled with zeros. But if signed data types are used, like e.g. INT, then an arithmetic shift will be executed in such cases, that means it will be filled with the value of the topmost bit.

Note

The amount of bits used for the arithmetic operation is determined by the data type of the input variable! If the input variable is a constant the smallest possible data type is used. The data type of the output variable has no effect at all on the arithmetic operation.

See in the following example in hexadecimal notation that you get different results for erg_byte and erg_word depending on the data type of the input variable (BYTE or WORD), although the values of the input variables in_byte and in_word are the same.

Example in IL:

LD  16#45
SHR 2
ST  erg_byte

Example in ST:

PROGRAM shr_st
VAR
in_byte : BYTE:=16#45;
in_word : WORD:=16#45;
erg_byte : BYTE;
erg_word : WORD;
n: BYTE :=2;
END_VAR
erg_byte:=SHR(in_byte,n); (* Result is 11 *)
erg_word:=SHR(in_word,n); (* Result is 0011 *)

Example in FBD:

../_images/f5a11c97437399950a3313905c72d969