ZX BASIC:Operators
Itinerary: Language Reference  
Up: Language Syntax  
Previous  Next 
Identifiers  Operators 
Contents 
Operators
Operators in ZX Basic ranges from arithmetical and logical to bitwise ones.
Arithmetic Operators
Arithmetic operators are left associative (like in Sinclair BASIC) and have the same precedence. The following are a list of arithmetic operators (lower precedence operators appears first):
 +,  (Addition, Subtraction)
Operator + (addition) can also be used with strings to perform string concatenation.
 *, /, Mod (Multiplication, Division and Modulo)
Note: Mod operator returns the modulus (the reminder) of x / y.
E.g. 12 mod 5 = 2. It does not exist in Sinclair BASIC.
Exponentiation
 ^ (Power). x^y returns x to the power of y.
Note: Unlike Sinclair Basic, this operator is right associative.
This is the usual behavior in mathematics. So in ZX BASIC,
2^3^2 = 2^(3^2) = 512
(notice the right associative parenthesis), whilst in Sinclair BASIC,
2^3^2 = (2^3)^2 = 64
which is wrong. If in doubt, use always parenthesis to enforce the desired evaluation order.
Logical Operators
Logicals operators are like in ZX Spectrum Basic. Their result can be either False (which is represented with 0) or True, which might be any other value. Don't expect True value number to be always 1. If you need 0/1 values for boolean evaluations, use strictboolean compiler option. This might add a little overhead to boolean evaluations, tough.
Operator arguments must be numbers and the result is an unsigned byte value. For binary operators, if arguments are of different types they are converted to a common type before being evaluated:
AND  OR  NOT  XOR  

Performs the Logical Conjunction and returns TRUE if and only if both arguments are TRUE.

Performs the Logical Disjunction and returns TRUE if any of the arguments is TRUE.

Performs the Logical Negation and returns TRUE if the arguments is False and vice versa.

Performs a logical XOR and returns TRUE if one of the arguments is true and one of the arguments is false. In essense, returns true if ONLY one of the arguments is true.
