Functional Operators. Commodore CBM 2001, PET 2001-8, CBM 8000, CBM 4000, CBM 3000
Oglas
Oglas
Thus, it is possible to use logical operators to test bytes for a particular bit pattern.
For instance, the AND operator may be used to "mask" all but one of the bits of a status byte at a machine I/O port. The OR operator may be used to "merge" two bytes to create a particular binary value. The following examples will help demonstrate how the logical operators work.
63 AND 16=16
15 AND 14 = 14
-1 AND 8=8
4 OR 2 = 6
10 OR 10= 10
-1 OR -2= -1
N O T X = - ( X + 1 )
63 = binary 1 1 1 11 1 and 16 = binary 10000, so 63 AND 16=16
15 = binary I 1 1 1 and 14 = binary 1 110, so 15 AND 14 = 14 ( binary 1110)
-1 =binary 1111111111111111 and 8 =binary 1000, so -1 AND
8=8
4 = binary 100 and 2 = binary 10, so 4 or 2 = 6 (binary 1 10)
10 = binary 1010, so 1010 OR 1010 = 1010 (10)
-1 =binary 1 1 1 1 1 11 1 111 11 11 1 and -2 = binary
111 11 11 11 11 11 110, so -1 or-2 = -1. The bit complement of sixteen zeros is sixteen ones, which is the two's complement representation of -1.
The two's complement of any integer is the bit complement plus one.
1.8.4 Functional Operators
A function is used in an expression to call a predetermined operation that is to be performed on an operand. Commodore BASIC has intrinsic functions that reside in the system, such as SQR (square root) or SIN (sine). All of BASIC's intrinsic functions are described in Chapter 3.
Commodore BASIC allows user defined functions that are written by the programmer.
See DEF FN, Section 2.12.
18
Prenesi
Oglas