Bitwise operation |= in C

| performs a bitwise OR on the two operands it is passed.

For example,

byte b = 0x0A | 0x50;

If you look at the underlying bits for 0x0A and 0x50, they are 0b00001010 and 0b01010000 respectively. When combined with the OR operator the result in b is 0b01011010, or 0x5A in hexadecimal.

|= is analogous to operators like += and -= in that it will perform a bitwise OR on the two operands then store the result in the left operator.

byte b = 0x0A;
b |= 0x50;

// after this b = 0x5A

Leave a Comment