SHR block

Short summary

Name

SHR

→POU type

→function

Category

Standard (safe), Bitstring

Conform to →IEC-standard

(error) currently restricted
(IEC demands ANY_INT for the input N and an error handling in case of values < 0 for input N.)

(plus) more possible than defined in IEC-standard
(IEC demands ANY_BIT only for the input IN and the return value.)

Graphical interface

Available since

version 1.10.0 (for Neuron Power Engineer) – initial variant: ANY_BIT for input IN and return value

version 1.23.0 (for Neuron Power Engineer) – enhancement: ANY_INT for input IN and return value

version 3.8.0 (for library Standard (safe)): block provided in this library

Functionality

The block returns the result of a bitwise shift to the right.

At input IN, enter the value to be shifted. At input N, enter the bits to right-shift the value. The bits cleared on the left are filled with 0.

Deviation from IEC-standard

If a negative value is connected to the input N, Neuron Power Engineer does not treat this as an error but performs an opposite shift, hence a shift to the left. This behavior is a deviation from the →IEC-standard that specifies that values < 0 for the input N are an error.

 Compare: "SAR block" for an arithmetic shift to the right.

Inputs, return value

 

Identifier

→Data type

Description

Inputs:

IN

 BOOLBYTEWORDDWORD or LWORD
(corresponds to →generic data type ANY_BIT
and
USINTUINTUDINTULINTSINTINTDINT or LINT
(corresponds to →generic data type ANY_INT

input value

N

INT

number of bits to shift

Return value:

 BOOLBYTEWORDDWORD or LWORD
(corresponds to →generic data type ANY_BIT
and
USINTUINTUDINTULINTSINTINTDINT or LINT
(corresponds to →generic data type ANY_INT

 

Input EN and output ENO are available when →calling the block. See "Execution control: EN, ENO" for information on input EN and output ENO.

See:

Example for usage within ST-editor

PROGRAM Test
    VAR
        result1, result2 : BYTE;
    END_VAR
    result1 := SHR(IN := 16#40, N := 1);       (* The variable 'result1' evaluates to '16#20'. *)
    result2 := SHR(IN := 16#80, N := 1);       (* The variable 'result2' evaluates to '16#40'. *)
END_PROGRAM

When creating your application within the ST-editor, enter a call of a block by typing the text as requested by the syntax or use Content Assist.