SHL

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

Syntax: erg := SHL (in, n)

in: Operand that is moved to the left.

n: Number of bits in move to the left.

SHL 1:

If n exceeds the width of the data type, it depends on the target system how BYTE, WORD, DWORD and LWORD operands are populated. The target systems cause padding with zeros or with n MOD <register width>.

SHL 2:

Note that the number of bits that TwinCAT takes into account for the arithmetic operation is determined by the data type of the input variable.

Examples:

The results for nResByte and nResWord are different, despite the fact that the values of the input variables nInByte and nInWord are the same, because the data types of the input variables are different.

ST:

PROGRAM Shl_st
VAR
    nInByte  :  BYTE:=16#45; (*2#01000101*)
    nInWord  :  WORD:=16#0045; (*2#0000000001000101*)
    nResByte :  BYTE;
    nResWord :  WORD;
    nVar : BYTE  := 2; 
END_VAR

nResByte := SHL(nInByte,nVar); (*Result is 16#14, 2#00010100*)
nResWord := SHL(nInWord,nVar); (*Result is 16#0114, 2#0000000100010100*)

FBD:

SHL 3: