Stu Pitt
Stu Pitt

Reputation: 45

Operator |= in C++ and its usage

While i was checking some C++ code i found a rather interesting operator and was wondering what it does? I tried finding it on the Internet but no luck.

index |= (image(y - 1, x) != 0) << 3;

The right-hand side is clear, it does a left shift by 3 bit if the result is not zero, but this |= operator on the left confuses me.

Upvotes: 0

Views: 264

Answers (1)

glenebob
glenebob

Reputation: 1983

In place bitwise OR. It updates the operand with the OR of the operand and the expression on the right.

Same as

index = index | (image(y - 1, x) != 0) << 3;

Upvotes: 3

Related Questions