Arduino Programming Language: BitwiseCompoundAnd

Name

&= (compound bitwise AND)

Description

The compound bitwise AND operator (&=) is often used with a variable and a constant to force particular bits in a variable to the LOW state (to 0). This is often referred to in programming guides as "clearing" or "resetting" bits.

Syntax

x &= y;   // equivalent to x = x & y;

Parameters

  • x: a char, int or long variable
  • y: an integer constant or char, int, or long

Usage

Application

Examples

First, a review of the Bitwise AND (&) operator:

unsigned int a = 60; // 60 = 0011 1100
unsigned int b = 13; // 13 = 0000 1101
unsigned int c = 0;
c = a & b; // 12 = 0000 1100

The compound bitwise AND combine bitwise AND with the assignment.

unsigned int a = 60; // 60 = 0011 1100
unsigned int b = 13; // 13 = 0000 1101
a &= b; // 12 = 0000 1100


Based on the reference originally written by Arduino Community,  wiring.org.co and  arduino.cc