L-force | plc designer – Lenze PLC Designer PLC Designer (R2-x) User Manual

Page 472

Advertising
background image

L-force | PLC Designer

IEC Operators and additional norm extending functions

470

DMS 3.2 EN 02/2011 TD29



Example in ST:

PROGRAM shl_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:=SHL(in_byte,n); (* Result is 16#14 *)

erg_word:=SHL(in_word,n); (* Result is 16#01141 *)

Example in FBD:

Example in IL:

LD 16#45

SHL 2

ST erg_byte

9.4.2

SHR

PLC Designer IEC operator: Bitwise right-shift of an operand: erg:= SHR (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!

Please note, that the amount of bits, which is regarded for the arithmetic operation,
is pretended by the data type of the input variable !. If the input variable is a
constant the smallest possible data type is regarded. The data type of the output
variable has no effect at all on the arithmetic operation.

See the following example in hexadecimal notation to notice the results of the
arithmetic operation depending on the type of the input variable (BYTE or WORD).

Advertising