Skip to content

Commit cd432c6

Browse files
authored
Update 662-language-and.markdown
1 parent 429cb93 commit cd432c6

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

_build/reference/662-language-and.markdown

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,49 @@
11
# AND
22

3-
> a AND b
3+
> n = a AND b
44
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
617

718
```
819
a = 1
920
b = 0
1021
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
1230
1331
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"
1533
1634
c = "test"
1735
1836
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
2043
```
2144

45+
### Example 3: Truth table for logical and bitwise operators
46+
2247
```
2348
? " < SmallBASIC - Truth Table > "
2449
?
@@ -156,13 +181,9 @@ n = 0xFFFFFFFF Band 0x7FFFFFFF
156181

157182
The code above produces different results on 32-bit and 64-bit systems;
158183
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
162185
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
166187
SmallBASIC integer is bit-31 (base 0). It is Safe to manipulate only
167188
bits 0 to 30, on both 64-bit and 32-bit systems. But it is Not safe
168189
to manipulate the sign bit, bit-31.

0 commit comments

Comments
 (0)