What does the "|=" operator mean? (with pipeline and no exclamation)

3

I was doing some research and came across the operator in |= sequence. See:

mBuilder.getNotification().flags |= Notification.FLAG_AUTO_CANCEL;

There is this operator in JAVA, but I do not know exactly if it follows the same syntax in other languages and I was in doubt.

What does the |= operator mean?

    
asked by anonymous 11.03.2017 / 17:17

1 answer

4

This applies the bitwise or operator to mBuilder.getNotification().flags and Notification.FLAG_AUTO_CANCEL and assigns the result to mBuilder.getNotification().flags .

Is the equivalent of:

mBuilder.getNotification().flags = mBuilder.getNotification().flags | Notification.FLAG_AUTO_CANCEL;

The binary operator OR, or binary disjunction, returns a bit 1 whenever at least one of the operands is '1'

Example:

int a = 60; //   60 = 0011 1100 
int b = 13; //   13 = 0000 1101 
int r = (a|b) // 61 = 0011 1101
    
11.03.2017 / 17:31