Bitwise Operations for IEC
See also: IEC 61131 Language Editor Programming
See also: Project Toolbox for IEC
Topic Menu
Home > View > Project Toolbox > Bitwise Operations
AND MASK 
Function - Performs a bit to bit AND between two register values.
Inputs
IN : ANY First input
MSK : ANY Second input (AND mask)
Outputs
Q : ANY AND mask between IN and MSK inputs
Remarks - In LD language, the EN signal enables the operation, and the ENO keeps the same value as the EN. In IL language, the first parameter (IN) must be loaded in the current result before calling the function. The other input is the operands of the function.
ST Language
Q := AND_MASK (IN, MSK) ;
FBD Language
LD Language
(* The function is executed only if EN is TRUE *)
(* ENO is equal to EN *)
IL Language
Return to the Top: Bitwise Operations for IEC
OR MASK 
Function - Performs a bit to bit OR between two register values
Inputs
IN : ANY First input
MSK : ANY Second input (OR mask)
Outputs
Q : ANY OR mask between IN and MSK inputs
Remarks - In LD language, the input rung (EN) enables the operation, and the output rung keeps the same value as the input rung. In IL language, the first parameter (IN) must be loaded in the current result before calling the function. The other input is the operands of the function.
ST Language
Q := OR_MASK (IN, MSK) ;
FBD Language
LD Language
(* The function is executed only if EN is TRUE *)
(* ENO is equal to EN *)
IL Language
Return to the Top: Bitwise Operations for IEC
Boolean XOR 
Function - Performs a bit to bit exclusive OR between two register values
Inputs
IN : ANY First input
MSK : ANY Second input (XOR mask)
Outputs
Q : ANY Exclusive OR mask between IN and MSK inputs
Remarks - In LD language, the input rung (EN) enables the operation, and the output rung keeps the same value as the input rung. In IL language, the first parameter (IN) must be loaded in the current result before calling the function. The other input is the operands of the function.
ST Language
Q := XOR_MASK (IN, MSK) ;
FBD Language
LD Language
(* The function is executed only if EN is TRUE *)
(* ENO is equal to EN *)
IL Language
Return to the Top: Bitwise Operations for IEC
NOT 
Function - Performs a bit to bit negation of an register value
Inputs
IN : ANY register input
Outputs
Q : ANY Bit to bit negation of the input
Remarks - In LD language, the input rung (EN) enables the operation, and the output rung keeps the same value as the input rung. In IL language, the parameter (IN) must be loaded in the current result before calling the function.
ST Language
Q := NOT_MASK (IN) ;
FBD Language
LD Language
(* The function is executed only if EN is TRUE *)
(* ENO is equal to EN *)
IL Language
Return to the Top: Bitwise Operations for IEC
Shift Left 
Function - Shift bits of a register to the left.
Inputs
IN : ANY register
N : ANY Number of shifts (each shift is 1 bit)
Outputs
Q : ANY Shifted register
Diagram
Remarks - In LD language, the EN signal enables the operation, and the ENO keeps the state of the EN. In IL language, the first input must be loaded before the function call. The second input is the operand of the function.
ST Language
Q := SHL (IN, NBS) ;
FBD Language
LD Language
(* The shift is executed only if EN is TRUE *)
(* ENO has the same value as EN *)
IL Language
Return to the Top: Bitwise Operations for IEC
Shift Right 
Function - Shift bits of a register to the right.
Inputs
IN : ANY register
N : ANY Number of shifts (each shift is 1 bit)
Outputs
Q : ANY Shifted register
Diagram
Remarks - In LD language, the EN signal enables the operation, and the ENO keeps the state of the EN. In IL language, the first input must be loaded before the function call. The second input is the operand of the function.
ST Language
Q := SHR (IN, NBS);
FBD Language
LD Language
(* The shift is executed only if EN is TRUE *)
(* ENO has the same value as EN *)
IL Language
Return to the Top: Bitwise Operations for IEC
Rotate Left 
Function - Rotate bits of a register to the left.
Inputs
IN : ANY register
N : ANY Number of rotations (each rotation is 1 bit)
Outputs
Q : ANY Rotated register
Diagram
Remarks - In LD language, the EN signal enables the operation, and the ENO keeps the state of the EN. In IL language, the first input must be loaded before the function call. The second input is the operand of the function.
ST Language
Q := ROL (IN, NBR) ;
FBD Language
LD Language
(* The rotation is executed only if EN is TRUE *)
(* ENO has the same value as EN *)
IL Language
Return to the Top: Bitwise Operations for IEC
Rotate Right 
Function - Rotate bits of a register to the right.
Inputs
IN : ANYregister
N : ANY Number of rotations (each rotation is 1 bit)
Outputs
Q : ANY Rotated register
Diagram
Remarks - In LD language, the EN signal enables the operation, and the ENO keeps the state of the EN. In IL language, the first input must be loaded before the function call. The second input is the operand of the function.
ST Language
Q := ROR (IN, NBR) ;
FBD Language
LD Language
(* The rotation is executed only if EN is TRUE *)
(* ENO has the same value as EN *)
IL Language
Return to the Top: Bitwise Operations for IEC
Bit Set 
Inputs
IN: Integer data type, typically an array.
LEN: The size of the block in bytes.
BIT: The number of the bit in the block to be set.
Outputs
Q : Bit valid. TRUE if the bit number is <= LEN x 8
This element sets a bit in a bit string (IN) to 1. Bit string length (LEN) can be between 1 to 512 bytes.
ST Language
OK1 := BITSET (In1, Len1, Bit1);
FBD Language
LD Language
IL Language
Not Available.
Return to the Top: Bitwise Operations for IEC
Bit Clear 
Inputs
IN: Integer data type, typically an array.
LEN: The size of the block in bytes.
BIT: The number of the bit in the block to be cleared.
Outputs
Q : Bit valid. TRUE if the bit number is <= LEN x 8
This element clears a bit in a bit string (INe) to 1. Bit string length (LEN) can be between 1 and 512 bytes.
ST Language
OK2 := BITCLEAR ( In2, Len2, Bit2) ;
FBD Language
LD Language
IL Language
Not Available
Return to the Top: Bitwise Operations for IEC
Bit Test 
Inputs
IN: Integer data type, typically an array.
LEN: The size of the block in bytes.
BIT: The number of the bit in the block to be tested.
Outputs
Q : Bit valid. TRUE if the bit number is <= LEN x 8 AND the bit specified is TRUE.
This element tests a bit in a bit string (IN) to 1. Bit string length (LEN) can be between 1 to 512 bytes.
ST Language
OK3 := BITSET (In3, Len3, Bit3);
FBD Language
LD Language
IL Language
Not Available
Return to the Top: Bitwise Operations for IEC