Block that performs a binary logical right shift operation in a value passed by Value, storing the result in Result.
Ladder Representation

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 shift |
|
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 shifts right, according to the Shift value.
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

Example in Ladder

The above example performs a logical right shift by two positions in the VALUE variable whose initial value is 124 (0111 1100 in binary). The bits on the right are being discarded, and on the left new zeros are inserted. The final result (0001 1111 in binary) is stored in RESULT.

The above example performs a logical right shift by three positions in the VALUE variable whose initial value is -98 (1001 1110 in binary). The bits on the right are being discarded, and on the left new zeros are inserted. The final result (0001 0011 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 : SINT := -98; SHIFT : BYTE := 3; RESULT : INT; END_VAR
RESULT := FB_SHR( EN:=DI1, Value:=VALUE, Shift:=SHIFT, ENO=>DO1);
|
|---|