Skip to main content

OR Operator

Introduction to OR Operator

1 min read

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
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

aba | b
000
011
101
111

Truth Table

aba | b
FalseFalseFalse
FalseTrueTrue
TrueFalseTrue
TrueTrueTrue

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

Reading Progress