Navigation:  Equipments (Devices) > SCA06 > Ladder > Logic > Logic Rotate >

ROL

Previous pageReturn to chapter overviewNext page

Block that performs a logical left rotation operation in a value passed by Value, storing the result in Result.

 

Ladder Representation

 

ROL_block

 

Block Structure

 

Variable Type

Name

Data Type

Description

VAR_INPUT

EN

BOOL

Block enabling

Value

BYTE USINT SINT WORD UINT INT DWORD UDINT DINT

Variable to undergo rotation

Shift

BYTE USINT

Shift index

VAR_OUTPUT

ENO

BOOL

End of operation

Result

BYTE USINT SINT WORD UINT INT DWORD UDINT DINT

Variable that stores the result of the operation

 

Operation

 

When this block has a TRUE value in EN, it sends to the Result output the value of the Value variable after performing a number of logical left shifts, according to the Shift value. The most significant bits that are being discarded are returned to the least significant bits, characterizing the rotation.

 

When EN has FALSE value, Result remains unchanged.

 

The ENO value forwards to the next Ladder block the EN value after the operation is completed.

 

Block Flowchart

 

ROL_flowchart

 

Example in Ladder

 

ROL_example01

 

The above example performs a logical left shift by one position in the VALUE variable whose initial value is -100 (1001 1100 in binary). The discarded bits on the left are reinserted on the right. The final result (0011 1001 in binary) is stored in RESULT.

 

ROL_example02

 

The above example performs a logical left rotation by five positions in the VALUE variable whose initial value is 21 (0001 0101 in binary). The discarded bits on the left are reinserted on the right. The final result (1010 0010 in binary) is stored in RESULT.

 

Example in ST

 

 The example below displays the instructions for applying the example above in the ST language.

 

 

VAR

   VALUE : USINT := 2#0001_0101;

   SHIFT : BYTE := 5;

   RESULT : USINT;

END_VAR

 

RESULT := FB_ROL(

   EN:=DI1,

   Value:=VALUE,

   Shift:=SHIFT,

   ENO=>DO1);