Bitshift Functions (E_)SHR
109
Description SHR shifts a bit value by a defined number of positions (N) to the right and fills the
vacant positions with zeros.
the 4 most significant bits are filled up with zeros
3
bit
bit
DT0
15 . . 12 11 . . 8 7. .4 . . 0
DT0 0 0 0 0
15 . . 12 11 . . 8 7. .4 3 . . 0
source register (N = 4 bits)
target register
For the difference between the normal IEC function and the function with an enable
input, see page 24. You can find an example for the “function with enable” in the
Online Help.
Data type I/O Function
BOOL, WORD, DWORD 1st input input value
BOOL, WORD, DWORD 2nd input number of bits by which the input value is shifted to the
right
BOOL, WORD, DWORD output as input result
If the second input variable N (the number of bits to be shifted) is of the data
type DWORD, then only the lower 16 bits are taken into account.
Example In this example the function SHR is programmed in instruction list (IL).
In the POU header, all input and output variables are declared that are used for
programming this function.
This example uses variables. You may also use a constant for the input variable.
Body The value for source_register are shifted N (3) bits to the right. The resulting vacant
bits are filled with zeros. The result is written in target_register.
IL
(E_)SHR Shift bits to the right