Skip to main content

Operator: SHL

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

erg := SHL (in, n)

in: Operand which is shifted to the left

n: Number of bits to shift in to the left

Important

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

Important

Note the number of bits which CODESYS uses for this operation as defined by the data type of the input variable in.

Example 118. Examples

The results for erg_byte and erg_word are different, although the values of the in_byte and in_word input variables are the same and the data types of the input variables are different.

ST

PROGRAM shl_st
VAR
  in_byte : BYTE := 16#45; (* 2#01000101 )
  in_word : WORD := 16#0045; (* 2#0000000001000101 )
  erg_byte : BYTE;
  erg_word : WORD;
  n: BYTE := 2;
END_VAR

erg_byte := SHL(in_byte,n); (* Result is 16#14, 2#00010100 *)
erg_word := SHL(in_word,n); (* Result is 16#0114, 2#0000000100010100 *)

FBD

_cds_img_shl.png