And運算子

執行2個數值的And運算(邏輯或位元)。

格式
result = 值1 And 值2

參數

值1、值2
用於在邏輯And運算中指定邏輯值的傳回值。在位元And運算中,用於指定整數運算式。
result
用於在邏輯And運算中傳回邏輯值。在位元And運算中,用於傳回整數。

說明
邏輯And運算用於結合2個以上的值,並導出Bolean型結果。下表所示為表示And運算的模式。

值1 值2 result
True True True
True False False
False True False
False False False

位元And運算用於以位元為單位對2個數值進行比較,並依下表將相應的位元導出為result。

值1的位元 值2的位元 result
0 0 0
0 1 0
1 0 0
1 1 1

參照
LShift、Mask、Not、Or、RShift、Xor

And運算子範例

Function LogicalAnd(x As Integer, y As Integer)

  If x = 1 And y = 2 Then
    Print "The values are correct"
  EndIf
Fend

Function BitWiseAnd()

  If (Stat(0) And &H800000) = &H800000 Then
    Print "The enable switch is open"
  EndIf
Fend

>print 15 and 7
7
>