Configuration | Rules 4.2.1.3.9 SA0052: Unusual shift operation | SA0052: Unusual shift operation Samples: PROGRAM MAIN VAR nINT : INT; nDINT : DINT; nULINT : ULINT; nSINT : SINT; nUSINT : USINT; nLINT : LINT; nDWORD : DWORD; nBYTE :
BYTE; END_VAR nINT := SHL(nINT, BYTE#2); // => SA0052 nDINT := SHR(nDINT, BYTE#4); // => SA0052 nULINT := ROL(nULINT, BYTE#1); // no error because this is an unsigned data type nSINT := ROL(nSINT, BYTE#2); // => SA0052 nUSINT := ROR(nUSINT, BYTE#3); // no error because this is an unsigned data type nLINT := ROR(nLINT, BYTE#2); // => SA0052 nDWORD := SHL(nDWORD, BYTE#3); // no error because DWORD is a bit field data type nBYTE := SHR(nBYTE, BYTE#1); // no error because BYTE is a bit field data type 4.2.1.3.10 SA0053: Too big bitwise shift | SA0053: Too big bitwise shift Samples: PROGRAM MAIN VAR nBYTE : BYTE; nWORD : WORD; nDWORD : DWORD; nLWORD :
LWORD; END_VAR nBYTE := SHR(nBYTE, BYTE#8); // => SA0053 nWORD := SHL(nWORD, BYTE#45); // => SA0053 nDWORD := ROR(nDWORD, BYTE#78); // => SA0053 nLWORD := ROL(nLWORD, BYTE#111); // => SA0053 nBYTE := SHR(nBYTE, BYTE#7); // no error nWORD := SHL(nWORD, BYTE#15); // no error TE1200 43 Version: 2.11.1 Function Determines shift operation (bit shift) on signed variables. However, the IEC 61131-3 standard only permits shift operations to bit fields. See also strict rule SA0147: Unusual shift operation - strict [} 70]. Reason TwinCAT allows shift operations on signed data types. However, such operations are unusual and can be confusing.
The IEC-61131-3 standard does not provide for such operations, so you should avoid them. Exception Shift operation on bit field data types (byte, DWORD, LWORD, WORD) do not result in a SA0052 error. Importance Medium Function Determines whether the data type width was exceeded in bitwise shift of operands. Reason If a shift operation exceeds the data type width, a constant 0 is generated. If a rotation shift exceeds the data type width, it is difficult to read and the rotation value should therefore be shortened. Importance High