AMSTRAD CPC464 User Manual page 103

Cpc464 colour personal computer 64k
Hide thumbs Also See for CPC464:
Table of Contents

Advertisement

This is because the numbers 10 and 1000 have been converted to binary representation:
1010
1 1 1 1 1 0 1 0 0 0
The AND operation checks each corresponding bit at a time, and where the bit in the top and the
bottom row is 1, the answer is 1:
0 0 0 0 0 0 1 0 0 0
. ..which when converted back to decimal notation is our result of 8. All this means that the logical
operator AND is used to detect when two conditions are present simultaneously. Here' s a self
explanatory application:
1 0 C L S : I N P U T " T h e n u m b e r o f t h e d a y " ; d a y
2 0 I N P U T " T h e n u m b e r o f t h e m o n t h " ; m o n t h
3 0 I F d a y = 2 5 A N D m o n t h = 1 2 G O T O 5 0
4 0 G O T O 1 0
5 0 P R I N T " M e r r y C h r i s t m a s ! "
OR works on bits as well, where the result is 1 unless both bits from the arguments are 0, in which
case the result is 0. Using the same numbers as for the AND example
P R I N T 1 0 0 0 O R 1 0
1002
Bitwise:
1 0 1 0
1 1 1 1 1 0 1 0 0 0
Resulting in the answer:
1111101010
And in the program example:
10 CLS:
2 0 I N P U T " T h e n u m b e r o f m o n t h " ; m o n t h
3 0 I F m o n t h = 1 2 O R m o n t h = 1 O R m o n t h = 2 G O T O 5 0
4 0 C L S : G O T O 1 0
5 0 P R I N T " I t m u s t b e w i n t e r "
1 0 CLS
2 0 I N P U T " T h e n u m b e r o f t h e m o n t h " ; m o n t h
3 0 I F N O T ( m o n t h = 6 O R m o n t h = 7 O R O R m o n t h = 8 ) G O T O 5 0
4 0 C L S : G O T O 1 0
5 0 P R I N T " I t c a n ' t b e s u m m e r ! "
The final major feature to consider is the fact that you can add together a number of logical
conditions to distill the facts yet further (up to the maximum line length) in fact:
10 CLS : I N P U T " T h e n u m b e r o f t h e d a y " ; d a y
2 0 I N P U T " T h e n u m b e r o f t h e m o n t h " ; m o n t h
3 0 I F N O T ( m o n t h = 1 2 O R m o n t h = 1 ) A N D d a y = 2 9 G O T O 5 0
4 0 C L S : G O T O 1 0
5 0 P R I N T " T h i s i s n e i t h e r D e c e m b e r n o r
J a n u a r y , b u t t h i s m i g h t b e a l e a p y e a r "
The result of a relational expression is either -1 or 0. The bit representation for -1 is all bits of the
integer = 1; for 0 all bits of the integer are 0. The result of a logical operation on two such arguments
will yield either -1 for True, or 0 for False.
Check this by adding line 60 to the above program:
6 0 P R I N T N O T ( m o n t h = 1 2 O R m o n t h = 1 )

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents