100BBasic instructions
7.10 Shift and Rotate
S7-1200 Programmable controller
232
System Manual, 11/2011, A5E02486680-05
Table 7- 142 SHL example for Word data
Shift the bits of a Word to the left by inserting zeroes from the right (N = 1)
IN
1110 0010 1010 1101
OUT value before first shift:
1110 0010 1010 1101
After first shift left:
1100 0101 0101 1010
After second shift left:
1000 1010 1011 0100
After third shift left:
0001 0101 0110 1000
7.10.2
Rotate instructions
Table 7- 143 ROR and ROL instructions
LAD / FBD
SCL
Description
out := ROL(
in:=_variant_in_,
n:=_uint_in);
out := ROR(
in:=_variant_in_,
n:=_uint_in);
Use the rotate instructions (ROR and ROL) to rotate the bit pattern of
parameter IN. The result is assigned to parameter OUT. Parameter N
defines the number of bit positions rotated.
ROR: Rotate bit pattern right
ROL: Rotate bit pattern left
1
For LAD and FBD: Click the "???" and select the data types from the drop-down menu.
Table 7- 144 Data types for the parameters
Parameter
Data type
Description
IN
Byte, Word, DWord
Bit pattern to rotate
N
UInt
Number of bit positions to rotate
OUT
Byte, Word, DWord
Bit pattern after rotate operation
●
For N=0, no rotate occurs. The IN value is assigned to OUT.
●
Bit data rotated out one side of the target value is rotated into the other side of the target
value, so no original bit values are lost.
●
If the number of bit positions to rotate (N) exceeds the number of bits in the target value
(8 for Byte, 16 for Word, 32 for DWord), then the rotation is still performed.
●
ENO is always TRUE following execution of the rotate instructions.
Table 7- 145 ROR example for Word data
Rotate bits out the right -side into the left -side (N = 1)
IN
0100 0000 0000 0001
OUT value before first rotate:
0100 0000 0000 0001
After first rotate right:
1010 0000 0000 0000
After second rotate right:
0101 0000 0000 0000