Java Program on Bitwise OR Operator

In the previous article we have discussed about Java Program on Bitwise AND Operator

In this article we are going to see the use Bitwise OR operator in Java.

Java Program on Bitwise OR Operator

Bitwise OR Operator:

Bitwise OR operator is a binary operator which is represented by | symbol. It performs manipulation on each bit of a number i.e. bit by bit OR operation. It means it returns 1 if either of the bit is 1 else it returns 0.

Bitwise OR Operator

Syntax: 

operand1 | operand2

Where,

  • operand1 refers to first operand
  • | refers to Bitwise OR operator
  • operand2 refers to second operand

Example:

A = 2 in binary 0010
B = 3 in binary 0011
A | B = 3 = 0011

Let’s see an program to understand it more clearly.

Approach:

  • Declare two number.
  • Perform Bitwise OR operation on them by using operator.
  • Print the result.
public class Main
{   
    public static void main(String[] args)   
    {   
        //declaring two numbers
        int a = 2, b = 3;   
        //performing Bitwise OR operation
        int result = a | b;
        //printing result
        System.out.println("a | b = "+result);   
    }  
}
Output:

a | b = 3

topics in a java programming language? Go with these ultimate Advanced java programs examples with output & achieve your goal in improving java coding skills.

Related Java Programs: