Arduino Programming Language: BitwiseCompoundOr

Name

|= (compound bitwise OR)

Description

The compound bitwise OR operator (|=) is often used with a variable and a constant to "set" (set to 1) particular bits in a variable.

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 OR (|) operator:

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

c = a | b; // 61 = 0011 1101

The compound bitwise OR combine bitwise OR with the assignment:

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

a |= b; // 61 = 0011 1101


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