L-force | plc designer – Lenze PLC Designer PLC Designer (R3-1) User Manual

Page 1054

Advertising
background image

L-force | PLC Designer

Programming Reference

1052

DMS 4.1 EN 03/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#0114 *)

Example in FBD:

Example in IL:

SHR
IEC Operator: Bitwise right-shift of an operand.

erg:= SHR (in, n)

in: Operand to be shifted to the right.
n: Number of bits, by which in gets shifted to the right.
If n exceeds the data type width, operands of type BYTE, WORD, DWORD and LWORD
will be filled with zeros, operands of signed data types, like for example INT, will get an
arithmetic shift, that means they will be filled with the value of the topmost bit.

Note: Please note, that the amount of bits, which is noticed 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 noticed. 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