shr32/16/8 (Function)

Top  Previous  Next

Architecture:

X32 / NX32 / NX32L

Device support:

ALL

Firmware version:

1.00 / 1.00.00


The bitwise shift function "shrxx" operates on the SINT, INT, and DINT data types. It will shift the value a number of bits to the right. Bits coming in from left 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 shr32 : DINT;
VAR_INPUT
  in : DINT;
  n : SINT;
END_VAR;
 
FUNCTION shr16 : INT;
VAR_INPUT
  in : INT;
  n : SINT;
END_VAR;
 
FUNCTION shr8 : 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#FF00;
  // Shift contents of a 4 bits to the right
  b := shr16(in:=a, n:=4);
  // b is now 16#0FF0
  ...
END;
 
END_PROGRAM;