3 bit-shift operators, 1 shl, 2 shr – Lenze DDS v2.3 User Manual

Page 276: 3 rol, Drive plc developer studio

Advertising
background image

Drive PLC Developer Studio

IEC 61131-3 Operators

12-6

l

DDS EN 2.3

12.3

Bit-shift operators

Types:

The operands of the following bit shift operators should be of type BYTE, WORD or DWORD.

12.3.1

SHL

Shifting the bits of an operand to the left

Example IL:
LD

1

SHL 1
ST

Var1

(* Var1 = 2 *)

A:= SHL (IN, N)

ST

Var1

(* Var1 = 2 *)

IN

is shifted to the left by

N

bits, and padded with zeros from the right.

12.3.2

SHR

Shifting the bits of an operand to the right

Example IL:
LD

32

SHL 2
ST Var1

(* Var1 = 8 *)

A:= SHR (IN, N)

ST Var1

(* Var1 = 8 *)

IN

is shifted to the right by

N

bits, and padded with zeros from the left.

12.3.3

ROL

Rotating the bits of an operand to the left

Example IL:
LD

2#1001_0011

ROL 3
ST

Var1

A:= ROL (IN, N)

ST

Var1

(* Var1 = 2#1001_1100 *

IN

is rotated by one bit position to the left

N

times, with the bit on the extreme left being reinserted

from the right.

Tip!

The number of bits for the arithmetic operation is specified by the data type of input variable IN. A
constant is considered as the lowest-order data type. The data type of the output variable has no
effect on the arithmetic operation.

Show/Hide Bookmarks

Advertising