SAR block

Short summary

Name

SAR

→POU type

→function

Category

IEC-block, BitstringEnh

Conform to →IEC-standard

images/s/b2ic8e/9012/1ca6q62/_/images/icons/emoticons/add.svg not defined in IEC-standard

Graphical interface

images/download/thumbnails/414780777/SAR-version-1-modificationdate-1534860796995-api-v2.png

Available since

  • version 1.20.0 (for logi.CAD 3) – initial variant: ANY_BIT for input IN and return value

  • version 1.23.0 (for logi.CAD 3) – enhancement: ANY_INT for input IN and return value

Functionality

The block returns the result of an arithmetic shift to the right .

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

Compare: "SHR block" for a logical shift to the right.

Inputs, return value


Identifier

→Data type

Description

Inputs:

IN

BOOL, BYTE, WORD, DWORD or LWORD(corresponds to →generic data type ANY_BIT)
and
USINT, UINT, UDINT, ULINT, SINT, INT, DINT or LINT(corresponds to →generic data type ANY_INT)

input value

N

SINT

number of bits to shift

Return value:

BOOL, BYTE, WORD, DWORD or LWORD(corresponds to →generic data type ANY_BIT)
and
USINT, UINT, UDINT, ULINT, SINT, INT, DINT 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.

Example for usage within ST-editor

PROGRAM Test
VAR
result : BYTE;
END_VAR
result := SAR(IN := 16#40, N := 1); (* The variable 'result' evaluates to '16#20'. *)
result := SAR(IN := 16#80, N := 1); (* The variable 'result' evaluates to '16#C0'. *)
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.