Binary Inclusive OR Assign Operator

We share below some examples on how to use Binary Inclusive OR Assign Operator in the Java programming language:

Binary Inclusive OR Assign With Literal

The operator denoted by |= will perform binary inclusive OR assign operation. The inclusive OR will usually result in a bigger number than the operand. This operation will perform inclusive OR with the variable and the given expression, and assign it back again to the variable. See below:
int a = 55;
a |= 27;
System.out.println(a);
Which is in contrast with XOR. Below is the output of the code above that performs inclusive OR on 55 and 27.
63

Binary Inclusive OR Assign With Another variable

Below is a simple example on using Inclusive OR between two variables:

int a = 29;
int b = 69;
a |= b;
System.out.println(a);

So the Inclusive OR between 29 and 69 is assigned to a and displayed below:
93

Binary Inclusive OR Assign With An Expression

This is an example of Binary Inclusive OR Assign With An Expression in Java:
int a = 150;
int b = 31;
a |= b * 2;
System.out.println(a);
The value of b which is 31 is multiplied by 2 giving us 62. The Inclusive OR between 150 and 62 is shown below:
190