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

Asked

Viewed 1,250 times

3

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

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 language and I was in doubt.

What the operator means |=?

1 answer

4


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

Is the equivalent of:

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.