OR Calculator

Calculate the bitwise OR of two numbers and see the result in binary, hex, octal and decimal.

Updated

decimal
Enter to calculate Esc to clear

OR Calculator

Our OR Calculator applies the OR operation to two numbers bit by bit, the same as a | b in code. Type the numbers in decimal, binary, octal or hex, choose a bit width from 1 to 64, and see the result in every format, with A, B and the result lined up so you can see where each 1 comes from.

Quick answer

A bitwise OR gives 1 wherever either number has a 1 in the same position, and 0 only where both have a 0. For 12 (1100) and 10 (1010), every column except the last has a 1, so 12 OR 10 = 1110 = 14. Enter any two numbers above and the calculator shows the result instantly.

  • Truth table: only 0 OR 0 gives 0; every other pair gives 1
  • In code: a | b (one bar; || is logical OR)
  • Main use: setting bits and combining flags, e.g. 4 | 2 | 1 = 7
  • Never smaller: for numbers of 0 or more, A OR B is at least the larger of A and B

What Is Bitwise OR?

OR is the logic operation that is true when at least one input is true. A bitwise OR applies it to every bit position of two binary numbers at once: bit 0 of A with bit 0 of B, bit 1 with bit 1, and so on, with no carrying between positions. In Boolean algebra it is written A + B or A ∨ B.

Because OR can only switch bits on, never off, it is the natural tool for setting bits. The number you OR with acts as a mask: its 1 bits are forced to 1 in the result, and its 0 bits leave the other number unchanged.

OR Truth Table

ABA OR B
000
011
101
111

Example Calculations

12 OR 10: 0000 1100 | 0000 1010 = 0000 1110 = 14
5 OR 3: 0000 0101 | 0000 0011 = 0000 0111 = 7
8 OR 4: 0000 1000 | 0000 0100 = 0000 1100 = 12 (same as 8 + 4)
0xF0 OR 0x0F: 1111 0000 | 0000 1111 = 1111 1111 = 255
−8 OR 255 (8-bit): 1111 1000 | 1111 1111 = 1111 1111 = 255 (−1 signed)

A useful identity: A OR B = A + B − (A AND B). For 12 and 10 that is 12 + 10 − 8 = 14. When the numbers share no 1 bits, as with 8 and 4, the AND is 0 and OR is plain addition.

Setting Bits with OR

TaskExpressionExample
Set bit kx | (1 << k)8 | (1 << 0) = 9
Combine flagsREAD | WRITE | EXEC4 | 2 | 1 = 7 (rwx)
Add a permissionmode | 0o0040o640 | 0o004 = 0o644
Join two bytes(hi << 8) | lo(0x12 << 8) | 0x34 = 0x1234
Make a number oddn | 112 | 1 = 13
Lowercase an ASCII letterc | 3265 (A) | 32 = 97 (a)

The last trick works because uppercase and lowercase ASCII letters differ only in bit 5 (value 32). Setting that bit with OR turns A to Z into a to z and leaves lowercase letters as they are.

OR in Programming Languages

C, C++, Java, C#, JavaScript, Python and Go all write bitwise OR as a single | and logical OR as || (Python uses the word or). JavaScript turns both sides into 32-bit signed integers first, which is why x | 0 is a common way to drop the fraction: 3.7 | 0 = 3 and −3.7 | 0 = −3. Python integers have no fixed width, so OR there never overflows. For AND, XOR, NAND, NOR and XNOR on the same numbers, use the Bitwise Calculator.

Key Terms

OR
1 when at least one input is 1 (inclusive OR).
XOR
Exclusive OR: 1 when exactly one input is 1.
Flag
A single bit that marks an on / off setting; OR combines flags.
Bit width
How many bits each number has, such as 8, 16, 32 or 64.
Two’s complement
The usual way to store negative numbers: −n in w bits is stored as 2w − n.

How to Use the OR Calculator

  1. Enter A and B. Type the two numbers in the “Number A” and “Number B” boxes. Pressing Enter in A moves you to B. Decimal numbers can be negative.
  2. Pick the number format. Choose Dec, Bin, Oct or Hex for both numbers, or type a 0b, 0o or 0x prefix and the format switches by itself. Switching format converts the numbers already typed, so 12 becomes 1100 in binary.
  3. Set the bit width. Use the 8, 16, 32 or 64 chips, or type any width from 1 to 64. The width only matters when a negative number is involved.
  4. Read the result. The OR appears as soon as both numbers are filled, in the same format you typed, with the working underneath (for example 12 OR 10 = 14, 1100 | 1010 = 1110). Below it, A, B and the result are lined up bit by bit, and a table gives the result in binary, hexadecimal, octal, unsigned and signed decimal.
  5. Copy the result. Press Copy to copy the result without the spaces between digit groups. Press Clear or Esc to start again.

Example: pick Oct, enter A = 640 and B = 4 with a 16-bit width, and the result is 644, the file mode with “read for others” added.

Who Can Use This Calculator?

ProgrammersCombining flags, setting bits and building values from bytes
System AdministratorsWorking out Unix file permission modes
StudentsBoolean logic, truth tables and two’s complement coursework
Electronics HobbyistsChecking OR gate logic, such as the 7432 chip

Frequently Asked Questions (FAQs)

What is a bitwise OR?

A bitwise OR compares two numbers one bit position at a time and gives 1 wherever at least one of the numbers has a 1. A position is 0 only when both numbers have a 0 there. In most programming languages it is written with a single vertical bar: a | b.

How do you calculate 12 OR 10?

Write both numbers in binary: 12 = 1100 and 10 = 1010. Compare each column and write 1 if either has a 1. Only the last column has two 0s, so 12 OR 10 = 1110 = 14.

What is the OR truth table?

0 OR 0 = 0, 0 OR 1 = 1, 1 OR 0 = 1 and 1 OR 1 = 1. The output is 0 only in the first row, when both inputs are 0. This is called inclusive OR, because 1 OR 1 is also 1.

What is the difference between OR and XOR?

They differ only when both bits are 1: OR gives 1, XOR (exclusive OR) gives 0. So 12 OR 10 = 14 (1110) but 12 XOR 10 = 6 (0110). You can compare them side by side in the Bitwise Calculator.

What is bitwise OR used for?

OR is used to set bits and combine flags. READ | WRITE | EXECUTE with values 4, 2 and 1 gives 7 (rwx). x | (1 << k) switches bit k on, (high << 8) | low joins two bytes into one 16-bit value, and in ASCII a letter OR 32 gives its lowercase form: 65 (A) | 32 = 97 (a).

Is OR the same as adding?

Only when the two numbers share no 1 bits: 8 OR 4 = 12 = 8 + 4. In general A OR B = A + B − (A AND B), so 12 OR 10 = 12 + 10 − 8 = 14. For numbers of 0 or more, the OR is never smaller than the larger of the two.

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

| is bitwise OR and works on every bit: 6 | 3 = 7. || is logical OR: it only asks whether either side is true (non-zero) and stops as soon as one is. In C, 6 || 3 is 1 (true). Python writes logical OR as the word or.

How does OR work with negative numbers?

Negative numbers are stored in two’s complement, so their sign bit is 1. OR can never clear a bit, so OR with a negative number always gives a negative result. In 8 bits, −8 is 1111 1000, and −8 OR 255 = 1111 1111, which is −1 signed (255 unsigned).

Is the OR Calculator free?

Yes. It is completely free, needs no sign-up, and can be used as many times as you like.

Try our OR Calculator to find the bitwise OR of any two numbers instantly.