alpha = 0: beta = 1: %a = %@0111 + INT
{alpha OR beta)}

%x=%x+INT{(INKEY$="P" OR
INKEY$="p")}-INT{(INKEY$="O" OR
INKEY$="o")}

Despite the presence of INT {...}, in order to avoid confusion and unexpected results that can make debugging1 very hard, it would be a good practice to not use one or more single letter standard variables when there's a possibility of a similarly named variable existing in its integer form and instead use a more easily identifiable name.

We discussed about using floating point literals and/or expressions within the integer expressions evaluator; what happens when we want to do the opposite, to use in other words an integer expression as a sub-expression within the standard expression evaluator?

As it happens, this is possible as long as it is started after any opening parenthesis or separating comma. For example:

x$=STR$(%a, %b, 5)
x=apples*pears+(%x(3))

There is a notable exception to that requirement. For the new BANK... functions (See Chapter 23 for details about BANK) in the standard expression evaluator, the bank number can be considered to be implicitly within parentheses, so it may be specified using an integer expression directly as follows:

x=2*PI*BANK %b PEEK myaddress

As we saw from the unary ! operator, bitwise operations on variables and arrays are pretty straightforward and involve manipulations of the individual bits of any number as represented in the ZX Spectrum Next's memory.

Shifting left or right involves moving the binary content of a variable x places (bits) to the left or right, padding from the right or left respectively with as many 0s as the places we shift the number for.

To illustrate bit shifting we can do the following example: Let's assign the decimal number 1201 first to an integer variable A, then manipulate its bits by shifting them left and right and printing the result so we can compare:

100 %A=1201
110 %A>>=3
120 %A<<=3
130 PRINT %A

This will return 1200 when run. To demonstrate what went on we could illustrate the expressions in two consecutive PRINT statements:

100 PRINT %1201>>3
110 PRINT %150<<3

1 Debugging is the programming process where you first attempt to ascertain if a program has errors, then to identify these errors and finally to remove them.


ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.