icon

OR Bitwise Operations

Last modified: 2023-08-29

Basic

Assume we want to OR operation 0100 and 1001.

0100
# OR
1001

# Result: 1101

We can do that using | operator in Python.

0b0100 | 0b1001
# 13 ('1101' in binary)

4 | 9
# 13 ('1101' in binary)

# Binary representation
bin(0b0100 | 0b1001)
# 0b1101