Bitwise OR
The OR operation compares the two values bit by bit.
A bit in the result has the value 1 if either input has the value 1 at that position.
OR is the operation that sets one or more bits.
Try bitwise OR in the bit editor
The result of 12 OR 10. Edit the expression or select a bit to flip it.
7
6
5
4
3
2
1
0
14
value · 8 bits · unsigned
- hex
- 0x0E
Bitwise OR step by step
Calculate 12 OR 10:
- Write the first value: 1100.
- Write the second value: 1010.
- Set each position that has the value 1 in either value.
- The result is 1110, which is 14.
The truth table of OR
| A | B | A | B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Where bitwise OR is used
A driver uses OR with a mask to set a bit in a control register.
OR combines several flags into one configuration value.
OR keeps every bit that was already set, so it is safe for a read and write sequence.
Bitwise OR: points to note
- OR never clears a bit. Use AND with an inverted mask to clear a bit.
- In C, | is the bitwise OR and || is the logical OR.
- OR with 0 does not change the value.
The full bit editor
The full editor holds many values, evaluates expressions across them, and reads live values from a serial port.
Open this value in the full editorQuestions about bitwise OR
- What is 12 OR 10?
- The result is 14. The bits are 1100 and 1010, which give 1110.
- How do I set one bit with OR?
- Apply OR between the value and a mask that has only that bit set. In C this is value |= mask.
- Can OR clear a bit?
- No. OR only sets bits. Use AND with an inverted mask to clear a bit.