SHL

Shift bits to the left

SHL shifts a bit value by a defined number of positions (N) to the left and fills the vacant positions with zeros.

Bit shift to the left, zero-filled on right:

  1.  (1) Bit position
  2.  (2) target register
  3.  (3) (n = 4 bit)
  4.  (4) n bits starting from bit position 0 are filled with 0s.

Parameters

Input

IN (BOOL, WORD, DWORD)

1st input: input value

N (BOOL, WORD, DWORD)

2nd input: number of bits by which the input value is shifted to the left

Output

Var_OUT (BOOL, WORD, DWORD)

Output as input: result

NOTE

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

POU header

All input and output variables used for programming this function have been declared in the POU header. The same POU header is used for all programming languages.

	VAR
		source_register: WORD:=0;
		target_register: WORD:=0;
	END_VAR

This example uses variables. You can also use a constant for the input variable.

LD body

The first N bits (here 4) of source_register are left-shifted, the vacant positions on the right are filled with zeros. The result is written into target_register.

BODY
    WORKSPACE
        NETWORK_LIST_TYPE := NWTYPELD ;
        ACTIVE_NETWORK := 0 ;
    END_WORKSPACE
    NET_WORK
        NETWORK_TYPE := NWTYPELD ;
        NETWORK_LABEL :=  ;
        NETWORK_TITLE :=  ;
        NETWORK_HEIGHT := 5 ;
        NETWORK_BODY
B(B_F,SHL!,Instance,9,1,14,5,,?DIN?DN?C);
B(B_VARIN,,source_register,7,2,9,4,);
B(B_VARIN,,4,7,3,9,5,);
B(B_VAROUT,,target_register,14,2,16,4,);
L(1,0,1,5);
        END_NETWORK_BODY
    END_NET_WORK
END_BODY

IL body

LD

source_register

SHL

4

ST

target_register

Modified on: 2019-01-24Feedback on this pagePanasonic hotline