Introduction to OR Operator
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
Table of Contents
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
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.
Gopi Gorantala Newsletter
Join the newsletter to receive the latest updates in your inbox.