Propeller Manual

Table Of Contents
2: Spin Language Reference – Operators
The above example NOTs %00101100 and writes the result, %11010011, to X.
Bitwise NOT becomes an assignment operator when it is the sole operator to the left of a
variable on a line by itself. For example:
!Flag
This would store the inverted value Flag back into Flag.
Be careful not to get Bitwise NOT ‘
!’confused with Boolean NOT ‘NOT’. Bitwise NOT is for
bit manipulation while Boolean NOT is for comparison purposes (see page 168).
Boolean AND ‘
AND’, ‘AND=
The Boolean AND ‘
AND’ operator compares two operands and returns TRUE (-1) if both values
are
TRUE (non-zero), or returns FALSE (0) if one or both operands are FALSE (0). Boolean AND
can be used in both variable and constant expressions.
Example:
X := Y AND Z
The above example compares the value of Y with the value of Z and sets X to either: TRUE (-1)
if both
Y and Z are non-zero, or FALSE (0) if either Y or Z is 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 and Z is true…”
Quite often this operator is used in combination with other comparison operators, such as in
the following example.
IF (Y == 20) AND (Z == 100)
This example evaluates the result of Y == 20 against that of Z == 100, and if both are true, the
Boolean AND operator returns
TRUE (-1).
Boolean AND has an assignment form,
AND=, that uses the variable to its left as both the first
operand and the result destination. For example,
X AND= True 'Short form of X := X AND True
Here, the value of X is promoted to TRUE if it is non-zero, then is compared with TRUE and the
Boolean result (
TRUE / FALSE, -1 / 0) is stored back in X. The assignment form of Boolean
AND may also be used within expressions for intermediate results; see Intermediate
Assignments, page 147.
Propeller Manual v1.1 · Page 167