Bitwise OR Calculator – Free

This bitwise OR calculator merges two binary numbers: the result has a 1 in every position where at least one input has a 1. Both values stay in your browser.

How to use the Bitwise OR Calculator tool

  1. Type a binary number into Input A, such as 1100.
  2. Type the bits you want to merge in into Input B, such as 1010.
  3. Select Calculate. Select Example first if you want the sample pair filled in for you.
  4. Read the combined value in the Result box. The sample pair produces 1110.
  5. Select Copy to copy it, or edit either input and select Calculate again.

How bitwise OR combines two numbers

OR looks at each column of the two operands and writes 1 if Input A, Input B or both contain a 1 there. It writes 0 only when both bits are 0. This is inclusive OR. Exclusive OR, or XOR, differs in one case: it returns 0 when both bits are 1.

A 1 in the mask always forces a 1 in the output, and a 0 leaves the other operand's bit as it was. That makes OR the operation for switching bits on without disturbing their neighbors.

Bitwise OR example: setting flags

Unix permission bits are a familiar case. Read is 100, write is 010 and execute is 001. ORing read with execute gives 101, which is the octal digit 5.

The second pair below sets bit 2 in a byte that already has bit 4 set. Bit 4 is untouched.

  100   (read)
| 001   (execute)
= 101   (read and execute, octal 5)

  00010000
| 00000100
= 00010100

OR is not addition

When the operands share no 1 bits, OR and addition give the same answer: 1000 OR 11 is 1011, and 8 + 3 is 11. When they overlap, the results differ. 0110 OR 0011 is 0111, which is 7, while 6 + 3 is 9. OR never carries into the next column, so a bit that is set in both inputs is simply set once.

That property makes OR idempotent: setting a flag that is already set changes nothing. Adding the flag a second time would corrupt the value.

Accepted input and result width

Each field takes between 1 and 65,536 characters of 0 and 1. Whitespace is ignored and a leading 0b is dropped. Other characters trigger an error message in place of a result.

If the two numbers differ in length, the shorter one is extended with zeros on the left. Zeros do not change an OR, so the high bits of the longer input pass straight through: 101 OR 11000 gives 11101. The result is as wide as the longer input and keeps any leading zeros.

Frequently asked questions

What is 1100 OR 1010 in binary?

It is 1110. The first column has a 1 in both numbers, the second only in 1100, the third only in 1010, and the last in neither. In decimal, 12 OR 10 equals 14.

What is the difference between | and || in code?

The single bar is bitwise OR: it merges the bits of two integers and always evaluates both sides. The double bar is logical OR: it works on truth values and stops at the first true operand. 4 | 2 is 6, whereas 4 || 2 just counts as true.

How do I set a specific bit with OR?

Build a mask that has a 1 at the target position and zeros elsewhere, then OR it with the value. To set bit 5 of 01000001, the ASCII letter A, OR it with 00100000. The result, 01100001, is lowercase a.

Can OR ever turn a 1 into a 0?

No. OR can only keep bits or switch them on. To switch bits off, use AND with an inverted mask. To flip them, use XOR.

Does the order of Input A and Input B matter?

No. OR is commutative, so swapping the two fields gives an identical result. It is also associative, which lets you combine three or more values by feeding each result back in as an input.

Why does the result keep leading zeros?

The calculator treats the longer input as a fixed-width word and prints every bit of it. If you enter 0011 and 0101 you get 0111 with its leading zero, so the result lines up with the operands.

Related tools