SHL
Function Name |
SHL (Shift Left) |
---|---|
Description |
Moves each bit n positions to the left, losing any characters that are moved from the start of the string and replacing them with 0s at the end. So, if the string is shifted 2 positions to the left, the first two bits are removed and two extra 0s are added to the end of the string to replace them. |
Arguments |
IN {ANY_BIT} Input 1 is a bit string N {ANY_INT} N is an integer that defines the number of positions the SHL function will move the characters. For more information on the data types for the inputs and outputs, see Data Type Hierarchy. |
Returns |
Output {Same data type as input} The Output is the number that represents the new binary string. |
Example:
Function Block Diagram - SHL:
The SHL function has two inputs. The top input (IN) is 146 which corresponds to the binary string of 10010010. The bottom input (N) is 3 which instructs the function to shift the bits left by 3 positions. The output is 144 which corresponds to the binary string 10010000.
So, the shift left function has deleted the first 3 bits and added 3 zeros to the end of the string:
Input String | 10010010 |
Shift Left x3 | 10010000 |
The binary string that results from 3 shifts left is 10010000 which corresponds to the decimal value of 84. So the value of the output is 84.
ST Program - SHL:
The SHL function is used to shift the positions of the bits in the Input string to the left, losing any characters that are shifted from the start of the string and replacing them with zeros at the end of the string:
- Output := SHL (IN, N);
Where Output, IN, and N are defined as variables earlier in the ST program.
Alternatively, you can use the following syntax:
- Output := SHL (IN:= 146, N:= 3);
Where the numbers are the input values (in this case, they are the same numbers as used in the Function Block Diagram example).