> ## Content Index
> Fetch the complete content index at: https://www.javahandbook.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Introduction to OR Operator
- URL: https://www.javahandbook.com/bitmask/introduction-to-or-operator/
- Published: 2024-06-16T07:26:43.000Z
- Updated: 2025-08-07T03:17:42.000Z
- Author: Gopi Gorantala
- Tags: OR Operator, #bitmask, #docs

OR operator compares each bit of the first operand to the second operand’s corresponding bit. If both bits are 0, the corresponding result bit is set to 0\. Otherwise, the corresponding result bit is set to 1

Let's see another Bitwise operator, 'OR'. This outputs 1 unless both inputs are 0.

### Introduction

Bitwise OR is the most commonly used logical Bitwise operator. It is represented by a sign (`|`).

OR operator is the same as the OR gate we studied in the chapter on digital electronics, as shown below:

### Sketch

![Logic OR gate](https://storage.ghost.io/c/00/01/0001b1c8-8c52-4cdb-b3c7-c0746bea790e/content/images/2025/08/OR-gate.svg)

Logic OR gate

### What is the Bitwise OR operator?

The Bitwise OR operator is denoted by `|`. When an OR gate is given with two inputs, the corresponding outputs will be:

- If two input bits are 0, the output is 0.
- In all other cases, it is 1\. For example
  - 1 | 0 => yields to 1.
  - 0 | 1 => yields to 1.
  - 1 | 1 => yields to 1.

So, Bitwise OR returns `1` if one of the inputs given is 1.

### Syntax:

It compares each bit of the **first operand** to the **second operand**’s corresponding bit. If both bits are 0, the corresponding result bit is set to 0\. Otherwise, the corresponding result bit is set to 1

### Bitwise | Table

| a | b | a \| b |
| - | - | ------ |
| 0 | 0 | 0      |
| 0 | 1 | 1      |
| 1 | 0 | 1      |
| 1 | 1 | 1      |

**Truth Table**

| a     | b     | a \| b |
| ----- | ----- | ------ |
| False | False | False  |
| False | True  | True   |
| True  | False | True   |
| True  | True  | True   |

Let’s see some Bitwise `OR` operator examples in the next lesson.