Java Bitwise OR Assignment
In Java, Bitwise OR Assignment Operator is used to compute the Bitwise OR operation of left and right operands, and assign the result back to left operand.
In this tutorial, we will learn how to use Bitwise OR Assignment operator in Java, with examples.
The syntax to compute bitwise OR a value of 2
and value in variable x
, and assign the result back to x
using Bitwise OR Assignment Operator is
</>
Copy
x |= 2
Example
In the following example, we take a variable x
with an initial value of 9
, add bitwise OR it with value of 2
, and assign the result to x
, using Bitwise OR Assignment Operator.
Main.java
</>
Copy
public class Main {
public static void main(String[] args) {
int x = 9;
//bitwise OR assignment
x |= 3;
System.out.println("x : " + x);
}
}
Output
x : 11
Conclusion
In this Java Tutorial, we learned about Bitwise OR Assignment Operator in Java, with examples.