FAQ
 
 
Cover  \ Exhibition  \ Learning  \ Reference  \ Download  \ Discourse   
      Language \ Environment \ Libraries \ Comparison
 
   
   
Abridged (A-Z) \ Complete (A-Z)  
   
  Reference for Processing (BETA) version 91+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.  
Name  

& (bitwise AND)

   
Examples  
int a = 207;   // In binary: 11001111 
int b = 61;    // In binary: 00111101 
int c = a & b; // In binary: 00001101 
println(c);    // Prints "13", the decimal equivalent to 00001101 


color argb = color(204, 204, 51, 255); 
// The sytax "& 0xFF" compares the binary 
// representation of the two values and 
// makes all but the last 8 bits into a 0. 
// "0xFF" is 00000000000000000000000011111111 
int a = argb >> 24 & 0xFF; 
int r = argb >> 16 & 0xFF; 
int g = argb >> 8 & 0xFF; 
int b = argb & 0xFF;        
fill(r, g, b, a); 
rect(30, 20, 55, 55); 

Description   Compares each corresponding bit in the binary representation of the values. For each comparison two 1's yeild 1, 1 and 0 yeild 0, and two 0's yeild 0. This is easy to see when we look at the binary representation of numbers

  11010110  // 214
& 01011100 // 92
--------
01010100 // 84

To see the binary representation of a number, use the binary() function with println().
   
Syntax  
value & value2
   
Parameters  
value1   int, char, byte

value2   int, char, byte

   
Usage   Web & Application
   
Related   | (bitwise OR)
binary()
 
 






   
 
Updated: Fri Jul 15 16:35:32 PDT 2005
 
 








Creative Commons License
 
  Processing is an open project initiated by Ben Fry and Casey Reas  
  © Info