We've already seen the standard arithmetic operators.
+, and subtraction,
-, operators use full 32-bit integers, but, for efficiency, multiplication,
*, and division,
/, use restricted values.
You can use
* only to multiply 16-bit integers, and the result will be a 32-bit integer.
Similarly, you can use
/ only to divide a 32-bit integer by a 16-bit integer, and the result will be a 16-bit integer.
The restrictions do not affect most calculations, but if you really need to use all 32-bit integers (and you can cope with overflows, etc.) you can use the
Mul(a,b) corresponds to
Div(a,b) corresponds to
We've also met the logic operators
OR, which we know are really bit-wise operators.
You can also use the functions
Or to do exactly the same as
So, for instance,
And(a,b) is the same as
a AND b.
The reason for these functions is because there are
Eor (bit-wise) functions, too (and there aren't operators for these).
Not(a) swaps one and zero bits, so, for instance,
Eor(a,b) is the exclusive version of
Or and does almost the same, except that
Eor(1,1) is 0 whereas
Or(1,1) is 1 (and this extends to all the bits).
Eor tells you which bits are different, or, logically, if the truth values are different.
There's a collection of other functions related to maths, logic or numbers in general:
Abs(9)is 9, and
Abs(-9)is also 9.
TRUEif expression represents an even number, and
FALSEotherwise. Obviously, a number is either odd or even!
TRUEif expression represents an odd number, and
Bounds(exp, minexp, maxexp)
The following code fragments are equivalent:
y:=Bounds(x, min, max) y:=IF x<min THEN min ELSE IF x>max THEN max ELSE x
ato 5 (since 26=(7*3)+5),
cto -5 and
dto -3. It is important to notice that if exp1 is negative then the modulus will also be negative. This is because of the way integer division works: it simply discards fractional parts rather rounding.
Rndfor the first time in your program you should call it with a negative number. This decides the starting point for the pseudo-random numbers.
Rnd, but returns values in the 32-bit range, not a specified range. The seed value is used to select different sequences of pseudo-random numbers, and the first call to
RndQshould use a large value for the seed.
%1011000. Shifting a number one bit to the left is generally the same as multiplying it by two (although this isn't true when you shift large positive or large negative values). (The new bits shifted in at the right are always zeroes.)
%0001011. For positive exp1, shifting one bit to the right is the same as dividing by two. (The new bits shifted in at the left are zeroes if exp1 is positive, and ones otherwise, hence preserving the sign of the expression.)
Long(addr), Int(addr), Char(addr)
CHARvalue at the address addr. These functions should be used only when setting up a pointer and dereferencing it in the normal way would make your program cluttered and less readable. Use of functions like these is often called peeking memory (especially in dialects of the BASIC language).
PutLong(addr,exp), PutInt(addr,exp), PutChar(addr,exp)
CHARvalue represented by exp to the address addr. Again, these functions should be used only when really necessary. Use of functions like these is often called poking memory.
Go to the Next or Previous section, the Detailed Contents, or the Amiga E Encyclopedia.