And
Operand And Operand
 
Parameters: NONE
Returns: NONE
 

      The And operator performs a logical (bitwise) And on the two specified operands. The AND operation takes each pair of bits from the two sides of the operator and evaluates when using the AND rule.

           AND RULE

           1 and 1 = 1
           1 and 0 = 0
           0 and 1 = 0
           0 and 0 = 0

      So when we AND a pair of bits, we only get ONE when both bits are set(one), all other combinations produce a zero.

      AND is most commonly used within IF decisions where we want to ensure that two (or more) comparisons within an expression are true (1) before executing the code inside.

  
; Create three variables
  A=100
  B=100
  C=100
  
; Use AND to merge the conditions results
; so the code inside the IF, will only
; run when both A=100   and B =100
  If A=100 And B=100
     Print "A and B equal 100"
  EndIf
  
  
; Use AND to merge the various conditions
; results
  If A=100 And B=100 And C=100
     Print "A, B and C equal 100"
  EndIf
  
  Sync
  WaitKey
  







FACTS:


      * The keyword And can be interchanged with the & symbol

      * AND is always bitwise.

      * Most graphics rendering commands include And blending rules. To set use InkMode






Mini Tutorial:


Bitwise operations And, Or and Xor


  
; bitwise And
  Print Bin$(43+ " And" : Print Bin$(58+ " ="
  Print Bin$(43 And 58)
  Print ""
  
; bitwise Or
  Print Bin$(43+ " Or" : Print Bin$(58+ " ="
  Print Bin$(43 Or 58)
  Print ""
  
; bitwise Xor
  Print Bin$(43+ " Xor" : Print Bin$(58+ " ="
  Print Bin$(43 Xor 58)
  
; Display the Screen and wait for the user to press a key
  Sync
  WaitKey
  




This example would output.

  
  %00000000000000000000000000101011 And
  %00000000000000000000000000111010 =
  %00000000000000000000000000101010
  
  %00000000000000000000000000101011 Or
  %00000000000000000000000000111010 =
  %00000000000000000000000000111011
  
  %00000000000000000000000000101011 Xor
  %00000000000000000000000000111010 =
  %00000000000000000000000000010001
  
  


 
Related Info: Comparisons | Inkmode | Not | NotInt | Operators | Or | SetBit | SwapBit | Xor :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com