Bitwise OR Operation
OR returns 1 when at least one input bit is 1; only 0|0 gives 0. Use OR to set flags and combine permissions without clearing others.
Why This Mathematical Concept Matters
Why: OR is one of three basic logic gates. Unix chmod uses OR: 4|2|1 = read|write|execute.
How: Compare each bit: if either is 1, result is 1. Only 0|0 gives 0.
- ●value | (1 << n) sets bit n without clearing others.
- ●chmod 755 = 4|2|1 for owner, 4|1 for group/others.
- ●OR is idempotent: A | A = A.
OR Operation — Bitwise Combining & Flag Setting
Set bits, combine permissions, merge colors. A | B = 1 when either bit is 1.
📐 Examples — Click to Load
Enter Values
⚠️For educational and informational purposes only. Verify with a qualified professional.
🧮 Fascinating Math Facts
Unix chmod uses OR: 4|2|1 = read|write|execute.
— POSIX
Red (FF0000) | Blue (0000FF) = Magenta (FF00FF).
— Graphics
📋 Key Takeaways
- • OR returns 1 when at least one input bit is 1; only 0|0 gives 0
- • Use OR to set flags — combine permission bits without clearing others
- • Bitwise | vs Logical ||: | operates on bits; || on booleans
- • OR is idempotent for same value: A | A = A
💡 Did You Know?
📖 How OR Works
OR compares each bit position. If either bit is 1, the result is 1. Only when both are 0 is the result 0.
bit 7: 1|1=1, bit 6: 0|1=1, bit 5: 1|0=1, ... bit 0: 1|0=1
🎯 Expert Tips
💡 Set flags without clearing
Use OR to enable bits: flags |= MASK. AND clears; OR sets.
💡 Combine permissions
read|write|execute = 4|2|1 = 7. Add permissions without touching others.
💡 Default values
value | default ensures all bits in default are set. Useful for config merging.
💡 Hex for readability
0xFF | 0x0F = 0xFF. Hex groups 4 bits — easier to reason about masks.
⚖️ OR vs AND vs XOR
| Operation | Result when | Use case |
|---|---|---|
| OR (|) | Either bit is 1 | Set flags, combine permissions |
| AND (&) | Both bits are 1 | Mask/clear bits, check flags |
| XOR (^) | Bits differ | Toggle bits, parity, swap |
❓ Frequently Asked Questions
What is the difference between logical OR (||) and bitwise OR (|)?
Logical OR (||) operates on boolean expressions and short-circuits — returns true/false. Bitwise OR (|) operates on each bit of integers and returns a new number. Use | for flags and masks.
How do I set a specific bit using OR?
OR with a mask that has 1 in the desired position: value | (1 << n) sets bit n. Example: 0 | 4 sets bit 2.
Can OR be used for file permissions?
Yes. Unix uses 4=read, 2=write, 1=execute. 4|2 = 6 gives read+write. chmod uses OR to add permissions.
Why does 255 | 0 = 255?
OR keeps all 1s from either operand. 255 = 11111111, 0 = 00000000. 1|0 = 1, so result is 11111111 = 255.
How does OR work with hexadecimal?
Same as binary — each hex digit is 4 bits. 0xFF | 0x0F = 0xFF. The operation is performed bit-by-bit.
When would I use OR instead of AND?
OR sets bits; AND clears/checks them. Use OR to enable options. Use AND to test if a flag is set (value & mask) or to clear bits.
Is OR commutative?
Yes. A | B = B | A. Order does not matter.
What is the OR truth table?
0|0=0, 0|1=1, 1|0=1, 1|1=1. Result is 1 whenever at least one input is 1.
📊 Bitwise OR by the Numbers
📚 Official Sources
⚠️ Disclaimer: This calculator is for educational and programming use. Bitwise operations on signed integers may behave differently across languages (two's complement). Verify results in your target environment.