ROL

The IEC operator is used for bitwise rotation of an operand to the left.

Permitted data types: BYTE, WORD, DWORD, LWORD

Syntax: erg := ROL (in, n)

TwinCAT moves n times to the left by 1 bit and at the same time adds the bit with the extreme left position on the right.

ROL 1:

The number of bits, which TwinCAT takes into account for the calculation, is determined by the data type of the input variable. If this is a constant, TwinCAT considers the smallest possible data type. The data type of the output variable has no effect on the arithmetic operation.

Examples:

The results for nResByte and nResWord are different, depending on the data type of the input variable, despite the fact that the values of the input variables nInByte and nInWord are the same.

ST:

PROGRAM Rol_st 
VAR 
    nInByte  : BYTE := 16#45; 
    nInWord  : WORD := 16#45;
    nResByte : BYTE; 
    nResWord : WORD; 
    nVar : BYTE := 2; 
END_VAR 

nResByte := ROL(nInByte,nVar); (*Result: 16#15*)
nResWord := ROL(nInWord,nVar); (*Result: 16#0114*)

FBD:

ROL 2: