User Guide
Operators
50
Axcess Programming Language
DEFINE_PROGRAM
IF (X < 5)
X = X + 1
ELSE
X = Ø
In this case, X acts like a counter. If X does not equal 5, its value is increased by one. Eventually X
will equal 5; the Else statement will set it back to 0.
Unlike relational operators, logical operators can appear more than once in an expression. For
example:
X = 2
Y = 7
Z = 12
IF ((X = 2) AND (Y > 4) OR (Z <= 8))
{
(* Statement 1 *)
}
Since the operators AND and OR have the same precedence, AND is evaluated first since it appears
first. Both (X = 2) and (Y > 4) are true, so the result of this part of the expression is true. If you treat
this part as one unit, you can see its result is actually the first condition of the OR operator.
Although the second condition (Z <= 8) is false, the entire expression is true since OR requires only
one condition to be true. As a result, Statement 1 is executed. Refer to the Precedence Among
Operators section on page 51 for more information.
Bitwise Operators
Bitwise operators perform the same logical operations mentioned earlier, but on a bit-by-bit basis.
These operators are BAND, BOR, BXOR, and BNOT. They are similar to logical operators. For
example, the keyword BAND performs a logical AND operation between two bytes on a bit-by-bit
basis. Instead of producing a true or false result, bitwise operations form a new byte. For example:
X = $A1 BAND $8A
The variable X now equals $8Ø (see FIG. 16). The AND operation is applied to the first bit of each
value (1 and 1), setting the first bit of the result to 1. This is done again for each bit of the values,
producing a new byte.
FIG. 16 BAND applies the logical operator And on a bit-by-bit basis. Since both bits are true in the first location,
the resulting bit is also true.