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 it
The result of 12 OR 10. Select a bit to change it. Change the bit width or the signed mode to see the effect.
Name or expression
ID0
ASCII
·
Binary
0b
0b00001110
Hex
0x
0x0E
Decimal
14
Shift
Name or expression
ID0
Binary
0b
Hex
0x
Decimal
ASCII
·
Shift
Sign
Bits
Endian
7
6
5
4
3
2
1
0
Worked example
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.
Where this 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.
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 tool
The full editor holds many values at the same time. It also evaluates expressions across them, and it reads live values from a serial port.
Open the full editorQuestions
- 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.