Math Fundamentals18 sections · 814 units
Open in Course

Bitwise OR (|)

At least one bit is 1

The OR operator (|) compares two numbers bit by bit. For each position, the result has a 1 if at least one input bit is 1. Only when both are 0 does the result have a 0.

Example: 121012 | 10. In binary, 12=110012 = 1100 and 10=101010 = 1010. Comparing: 11=11|1=1, 10=11|0=1, 01=10|1=1, 00=00|0=0. Result: 1110=141110 = 14.

OR is how you set bits. If you want to make sure bit 3 is turned on, you OR the number with 23=82^3 = 8.