shl32/16/8 (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


The bitwise shift function "shlxx" operates on the SINT, INT, and DINT data types. It will shift the value a number of bits to the left. Bits coming in from the right are always 0.

 

Input:

in : DINT/INT/SINT

The value to shift.

 

n : SINT (0..32/16/8)

The number of bits to shift.

 

Returns: DINT/INT/SINT

The resulting value.

 

Declaration:

 

FUNCTION shl32 : DINT;
VAR_INPUT
  in : DINT;
  n : SINT;
END_VAR;
 
FUNCTION shl16 : INT;
VAR_INPUT
  in : INT;
  n : SINT;
END_VAR;
 
FUNCTION shl8 : SINT;
VAR_INPUT
  in : SINT;
  n : SINT;
END_VAR;

 

Example:

INCLUDE rtcu.inc
 
VAR
  a : INT;
  b : INT;
END_VAR;
 
PROGRAM test;
 
BEGIN
  a := 16#0FF0;
  // Shift contents of a 4 bits to the left
  b := shl16(in:=a, n:=4);
  // b is now 16#FF00
  ...
END;
 
END_PROGRAM;