EasyManua.ls Logo

Sinclair ZX81 - Chapter 4 - The Sinclair ZX81 as a calculator

Sinclair ZX81
92 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Chapter 4 - The Sinclair ZX81 as a calculator
Turn the computer on. You can now use it as a calculator, along the lines of chapter 2: type
PRINT
, then
whatever it is that you want working out, & then
NEWLINE
. (We shan't usually bother to tell you to type
NEWLINE
.)
As you would hope, the ZX81 can not only add, but also subtract, multiply using a star * instead of the
usual times sign - this is fairly common on computers) & divide (using / instead of ). Try these out.
+, -, * and / are operations
, & the numbers they operate on are their operands.
The computer can also raise one number to the power of another using the operation
**
(Shifted H. Do
not type * - shifted B - twice): type
PRINT
2
**
3 (Remember the
NEWLINE
.)
& you will get the answer 8 (2 raised to the power 3, or 2
3
, or 2 cubed)
The ZX81 will also work out combinations of the operations. For instance.
PRINT
20-2*3
**
2+4/2*3
gives the answer 8. It goes all round the houses to get this, because first it works out all the powers (
**
) in
order from left to right, & then all the multiplications & divisions (* & /), again from left to right, & then the
additions & subtractions (+ & -), yet again from left to right. Thus our example is worked out in the following
stages:
We formalize this by giving each operation a priority
, a number between 1 & 16. The operations with
highest priority are evaluated first, & operations with equal priority are evaluated in order from left to right.
When - is used to negate something, as when you write -1, then it has priority 9. (This is unary
minus, as
opposed to the binary
minus in 3-1: a unary operation has one operand, while a binary operation has two.
Note that on the ZX81 you cannot use + as a unary operation.)
This order is absolutely rigid, but you can circumvent it by using brackets: anything in brackets is
evaluated first & then treated as a single number, so that
PRINT
3*2+2
gives the answer 6+2 = 6, but
**
has priority 10
* and / have priority 8
+ & - have priority 6

Other manuals for Sinclair ZX81

Related product manuals