2.0 3.0 > lang > and
قبلی  بعدی  ویرایش  تغییر نام  واگرد  Search  سرپرستی
 مستندات
اخطار! این صفحه ترجمه نشده است.  مشاهده نسخه انگلیسی
AND
`Result = Expression AND Expression`

Depending on the expression, the AND operation can be either a logical AND or a numerical AND. In case of two boolean expressions, a logical AND operation is performed. In case of two integer numbers, a numerical AND operation is performed.

The logical AND operator takes two boolean expressions and returns a true or false value. The results returned by this operator is shown in the following table:

A B A AND B
FALSE FALSE FALSE
FALSE TRUE FALSE
TRUE FALSE FALSE
TRUE TRUE TRUE

The numerical AND operator takes two integer values and returns an integer value. Each corresponding bit of the specified values are combined according to the following table:

A B A AND B
0 0 0
0 1 0
1 0 0
1 1 1

The numerical AND operator can be used to test the bit pattern of a number. It can also be used to mask out selected bits of a number. The following table gives some examples of how the AND operator works on two integer numbers.

Expression Explanation
10 AND 20 = 0 10 = binary 01010
20 = binary 10100
Hence 10 AND 20 = 0

10 AND -20 = 8  10 = binary 00000000000000000000000000001010
-20 = binary 11111111111111111111111111101100
Hence 10 AND -20 = 8 (binary 1000)

20 AND -20 = 4  20 = binary 00000000000000000000000000010100
-20 = binary 11111111111111111111111111101100
Hence 20 AND -20 = 4 (binary 100)

### مثال

PRINT TRUE AND FALSE

False

PRINT TRUE AND TRUE

True

PRINT 7, Bin(7, 16)
PRINT 11, Bin(11, 16)
PRINT 7 AND 11, Bin(7 AND 11, 16)

7       0000000000000111
11      0000000000001011
3       0000000000000011

DIM A, B AS BOOLEAN

A = 10 < 20
B = 20 > 30

IF A AND B THEN
PRINT "Both A and B are TRUE"
ELSE
PRINT "Either A or B or both are FALSE"
ENDIF

Either A or B or both are FALSE

### همچنین مشاهده کنید

عملگرهاي رياضي, عملگرهاي منطقي, IF