|
1 | 1 | # AND |
2 | 2 |
|
3 | | -> a AND b |
| 3 | +> n = a AND b |
4 | 4 |
|
5 | | -Logical AND. Right side is not evaluated if left side evaluates to False. |
| 5 | +Logical AND. Right side is not evaluated if left side evaluates to FALSE. |
| 6 | + |
| 7 | +Truth table: |
| 8 | + |
| 9 | +| a | b| a AND b | |
| 10 | +|:-:|:-:|:------:| |
| 11 | +| 0 | 0 | 0 | |
| 12 | +| 0 | 1 | 0 | |
| 13 | +| 1 | 0 | 0 | |
| 14 | +| 1 | 1 | 1 | |
| 15 | + |
| 16 | +### Example 1 |
6 | 17 |
|
7 | 18 | ``` |
8 | 19 | a = 1 |
9 | 20 | b = 0 |
10 | 21 |
|
11 | | -print a and b ' output is 0 |
| 22 | +print a and b ' Output: 0 |
| 23 | +``` |
| 24 | + |
| 25 | +### Example 2: Using AND in an if-statement |
| 26 | + |
| 27 | +``` |
| 28 | +a = 1 |
| 29 | +b = 0 |
12 | 30 |
|
13 | 31 | if(a == 1 and b == 0) then print "if statement 1" |
14 | | -if(a == 1 and b == 1) then print "if statement 2" ' "if statement 2" will not be printed to the screen |
| 32 | +if(a == 1 and b == 1) then print "if statement 2" |
15 | 33 |
|
16 | 34 | c = "test" |
17 | 35 |
|
18 | 36 | if(a == 1 and c == "test") then print "if statement 3" |
19 | | -if(a == 1 and c == "test2") then print "if statement 4" ' "if statement 4" will not be printed to the screen |
| 37 | +if(a == 1 and c == "test2") then print "if statement 4" |
| 38 | +
|
| 39 | +
|
| 40 | +' Output: |
| 41 | +' if statement 1 |
| 42 | +' if statement 3 |
20 | 43 | ``` |
21 | 44 |
|
| 45 | +### Example 3: Truth table for logical and bitwise operators |
| 46 | + |
22 | 47 | ``` |
23 | 48 | ? " < SmallBASIC - Truth Table > " |
24 | 49 | ? |
@@ -156,13 +181,9 @@ n = 0xFFFFFFFF Band 0x7FFFFFFF |
156 | 181 |
|
157 | 182 | The code above produces different results on 32-bit and 64-bit systems; |
158 | 183 | Therefore it leads to subtle bug with no run-time error, and no other |
159 | | -indication. |
160 | | - |
161 | | -The reason for this inconsistency is the fact that SamllBASIC determine |
| 184 | +indication. The reason for this inconsistency is the fact that SamllBASIC determine |
162 | 185 | the type of variables on the fly. And while the sign bit in a 64-bits |
163 | | -register is bit-63 - in a 32-bits register is bit-31. |
164 | | - |
165 | | -SmallBASIC integers are 32-bit signed integers. The sign bit of |
| 186 | +register is bit-63 - in a 32-bits register is bit-31. SmallBASIC integers are 32-bit signed integers. The sign bit of |
166 | 187 | SmallBASIC integer is bit-31 (base 0). It is Safe to manipulate only |
167 | 188 | bits 0 to 30, on both 64-bit and 32-bit systems. But it is Not safe |
168 | 189 | to manipulate the sign bit, bit-31. |
|
0 commit comments