I just came across the following line inside some sourcecode.
int sequ |= element.sequence
What does the operator |= mean ? I haven't seen that before.
I just came across the following line inside some sourcecode.
int sequ |= element.sequence
What does the operator |= mean ? I haven't seen that before.
=|
is a compound assignment operator, similar to +=
, -=
, /=
, or *=
, but with bitwise OR instead.
This is equivalent to:
sequ = (int) (sequ | element.sequence);
where |
is the bitwise OR operation, meaning that it independently ORs all bits in the left operand with those in the right operand, to get a result. The cast is not necessary if element.sequence
is already an int
.
Note: Your original code wouldn't make sense:
int sequ |= element.sequence
You can't declare it there and then and or it with something else. It would need to have been declared and assigned before, such as in:
int sequ = 0; /* or some other value */
sequ |= element.sequence;
It is short form for:
int sequ = sequ | element.sequence;
Similar to +=
, -=
except that it is bitwise OR operator.