GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Processing
  • Download
  • Reference
  • Environment
  • Libraries
  • Tools
  • Wiki
  • Tutorials
  • Examples
  • Books
  • Forum
  • Overview
  • People
  • Privacy

This view

  • Original page
  • New address

GeezerVison is showing processing.org — & (bitwise AND) / Reference

Reference+
Documentation→Reference→Math→Bitwise Operators

Name

& (bitwise AND)

Description

Compares each corresponding bit in the binary representation of the values. For each comparison two 1's yield 1, 1 and 0 yield 0, and two 0's yield 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().

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);
    

Parameters

  • value1int, char, byte
  • value2int, char, byte

Related

  • bitwiseOR
  • binary()
Creative Commons License

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.