About the OR Calculator
Bitwise OR walks both operands one column at a time and writes a 1 wherever at least one of them already had a 1. Nothing is ever cleared, so OR is how flag constants get combined into a single integer: READ | WRITE produces a value that carries both permissions. This page shows that merge as a stacked bit layout so it is obvious which operand contributed each column.
Operands can arrive in decimal, or carry a 0x, 0b or 0o prefix when hex, binary or octal is more natural. Fixing the input base makes every line parse the same way, which saves prefixing a long list. Multiple lines in a pane are folded together, so a whole set of feature flags can be merged into one constant without chaining pipes by hand.
The result is printed four ways plus a signed reading for the chosen word size, and a closing line names every bit position left standing with its place value. Word size defaults to the narrowest of 8, 16, 32 or 64 bits that holds the inputs. Pick a fixed width when you are matching a register layout or a protocol header. Removing a flag needs AND with an inverted mask, so pair this page with the NOT Calculator and the AND Calculator. Octal permission bits are easier to read through the Unix Permission Calculator.
How to use
- Enter the first flag or value in the Operand A pane.
- Enter the value you want merged into it in the Operand B pane.
- Add more lines to either pane to merge several flags at once.
- Copy the decimal or hex line for use as a single combined constant.
Common questions
- What is the difference between OR and XOR?
- OR leaves a column set when both operands hold a 1, while XOR clears it. OR only ever adds bits; XOR toggles them.
- How do I set a single bit?
- OR the value with 1 shifted into that position, for example 0b00001000 to switch on bit 3. Bits that were already on stay on.
- Does the order of the operands matter?
- No. OR is commutative and associative, so any order of the same operands gives the same result.
- Why is the result larger than both inputs?
- OR unions the set bits of every operand, so the answer is at least as large as the biggest input and often larger.