
User Manual
Chapter 11
GFK-1742F
Jan 2020
Local Logic Tutorial
279
11.4.3
Bitwise Logical Operators
Bitwise logical operators mask or invert an individual bit or groups of bits. The BWAND (and),
BWOR (or), BWXOR (exclusive or), and BWNOT (ones-complement) operators are valid
constructs. BWAND, BWOR, and BWXOR require two operands. The BWNOT operator
requires one operand.
As an example, the following code segment isolates a copy of several bits in the
CTL_1_to_32 word and assigns them to a parameter register.
Then, the least significant four bits of that value are tested and P002 is assigned a value 4985
if any are set.
P001 := CTL_1_to_32 BWAND 16#0000A005;
IF P001 BWAND 16#F THEN
P002 := 4985;
END_IF;
Specifically, the statements perform the following operations. The first statement uses
16#0000A005 as a mask. The mask corresponds to a binary value as follows:
16# 0000A005 = 2#0000 0000 0000 0000 1010 0000 0000 0101
Thus, the statement
P001:=CTL_1_to_32 BWAND 16#0000A005
isolates bits 1,3,14, and 16 from CTL_1_to_32 and places the result in P001.
The next statement performs a bitwise test to see if any of the bits in the least significant
byte are set. The test value corresponds to a binary value as follows:
16#F = 2#1111
Thus the statement
IF P001 BWAND 16#F THEN
performs a bitwise test with the least significant byte of P001 and if any of the bits in the
least significant byte are set to a logical true (value = 1) then statements in the IF block are
evaluated.
In this example, since CTL_1_to_32 is masked in the previous statement, the IF condition
only tests bit 1 and bit 3 of CTL_1_to_32.