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.
Did our AI summary help? Let us know.
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.
Ready to run the numbers?
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.
Run the calculator when you are ready.
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.
Related Calculators
N O R Calculator
N O R Calculator - calculate and analyze with detailed results.
MathematicsAntilog Calculator
Antilog Calculator - calculate and analyze with detailed results.
MathematicsCircle Calculator
Circle Calculator - calculate and analyze with detailed results.
MathematicsCycloid Calculator
Cycloid Calculator - calculate and analyze with detailed results.
MathematicsMiracle Calculator
Miracle Calculator - calculate and analyze with detailed results.
MathematicsPercentage Calculator
Percentage Calculator - calculate and analyze with detailed results.
Mathematics