Propeller Manual

Table Of Contents
Operators – Spin Language Reference
Be careful not to get Boolean AND ‘AND’ confused with Bitwise AND ‘&’. Boolean AND is
for comparison purposes while Bitwise AND is for bit manipulation (see page 164).
Boolean OR ‘
OR’, ‘OR=
The Boolean OR ‘
OR’ operator compares two operands and returns TRUE (-1) if either value is
TRUE (non-zero), or returns FALSE (0) if both operands are FALSE (0). Boolean OR can be used
in both variable and constant expressions. Example:
X := Y OR Z
The above example compares the value of Y with the value of Z and sets X to either: TRUE (-1)
if either
Y or Z is non-zero, or FALSE (0) if both Y and Z are zero. During the comparison, it
promotes each of the two values to -1 if they are non-zero, making any value, other than 0, a -
1, so that the comparison becomes: “If
Y is true or Z is true…”
Quite often this operator is used in combination with other comparison operators, such as in
the following example.
IF (Y == 1) OR (Z > 50)
This example evaluates the result of Y == 1 against that of Z > 50, and if either are true, the
Boolean
OR operator returns TRUE (-1).
Boolean OR has an assignment form,
OR=, that uses the variable to its left as both the first
operand and the result destination. For example,
X OR= Y 'Short form of X := X OR Y
Here, the value of X is promoted to TRUE if it is non-zero, then is compared with Y (also
promoted to
TRUE if non-zero) and the Boolean result (TRUE / FALSE, -1 / 0) is stored back in X.
The assignment form of Boolean OR may also be used within expressions for intermediate
results; see Intermediate Assignments, page 147.
Be careful not to get Boolean OR ‘OR’ confused with Bitwise OR‘|. Boolean OR is for
comparison purposes while Bitwise OR is for bit manipulation (see page 165).
Boolean NOT ‘
NOT
The Boolean NOT ‘
NOT operator returns TRUE (-1) if the operand is FALSE (0), or returns
FALSE (0) if the operand is TRUE (non-zero). Boolean NOT can be used in both variable and
constant expressions. Example:
X := NOT Y
Page 168 · Propeller Manual v1.1