Skip to content
Math

OR Calculator (Bitwise)

Enter two integers in any base (decimal, binary, hexadecimal, or octal) and this calculator computes their bitwise OR. Results appear instantly in all four number systems. The "Show your work" panel lines up the bits column by column so you can follow exactly which positions fire.

Your details

Choose how you want to enter the two operands.
First non-negative integer. Enter in the base selected above.
Second non-negative integer. Enter in the base selected above.
Pad the binary display to a fixed width. "Auto" uses the fewest bits needed.
Result (decimal)
61

Bitwise OR result in base 10

Result (binary)00111101
Result (hexadecimal)3D
Result (octal)75
A in decimal60
B in decimal13
Bits in result6
A (decimal)60
B (decimal)13
A OR B61

60 OR 13 = 61

  • A OR B = 61 (decimal) = 00111101 (binary).
  • The result needs 6 bits to represent in binary.

Next stepBitwise OR is commonly used in systems programming to set specific flags without disturbing others - for example, enabling a permission bit in a Unix file mode or combining CSS colour channels.

Formula

R=AB(bitwise OR, biti:ri=aibi)R = A \mid B \quad (\text{bitwise OR, bit}_i: r_i = a_i \lor b_i)

Worked example

A = 60 (decimal) = 0011 1100 (binary). B = 13 (decimal) = 0000 1101 (binary). Applying OR: 0011 1100 | 0000 1101 = 0011 1101 = 61 (decimal) = 0x3D.

What is a bitwise OR operation?

A bitwise OR (written | in most programming languages) compares two integers bit by bit. For each bit position, the output is 1 if at least one of the two corresponding input bits is 1; the output is only 0 when both bits are 0. This is the logical OR rule applied in parallel across every bit of the number. Because OR can only switch bits on and never off, the result is always greater than or equal to either operand.

How to use this calculator

Select the base in which you want to enter your numbers (decimal, binary, hexadecimal, or octal), then type the two operands. The result appears instantly in all four bases. Use the bit-width selector to control how many digits the binary output is padded to - 8-bit is convenient for a single byte, 32-bit matches a standard integer. The "Show your work" panel displays the column-by-column bit alignment so you can verify each position manually.

Common uses of bitwise OR

Setting a specific flag: if you have a flags variable and want to enable bit 3, you OR it with the mask 0b00001000 (= 8). Any bits that were already set remain set, and bit 3 turns on. This pattern is the standard way to enable Unix file permissions (chmod uses octal masks), combine hardware status registers, merge colour channels in image processing (red | blue = 0xFF0000 | 0x0000FF = 0xFF00FF), and pack multiple boolean fields into a single integer for compact storage.

OR vs AND vs XOR at a glance

Bitwise AND (&) keeps a bit only when both inputs have it - used to isolate or test flags. Bitwise OR (|) sets a bit when either input has it - used to combine or add flags. Bitwise XOR (^) sets a bit when exactly one input has it - used to toggle flags or compute differences. NOT (~) inverts all bits and is used together with AND to clear flags. Knowing which operation to reach for is a core skill in systems and embedded programming.

Bitwise OR truth table

Bit ABit BA OR B
00 0
01 1
10 1
11 1

Output for every combination of single input bits A and B.

Frequently asked questions

What does the bitwise OR operator do?

It combines two integers bit by bit. Each output bit is 1 if at least one of the two input bits in that position is 1, and 0 only when both input bits are 0. The mathematical result is always greater than or equal to both input values.

Why does OR never decrease a number?

OR can only turn bits on, never off. Every bit that is 1 in either input stays 1 in the output. Bits that are 0 in both inputs stay 0. So the result has at least as many 1-bits as either operand, meaning it is always greater than or equal to the larger of the two inputs.

What is 60 OR 13 in binary?

60 in binary is 0011 1100 and 13 is 0000 1101. Comparing each column: the result is 0011 1101, which is 61 in decimal and 0x3D in hexadecimal. This is the default example loaded in the calculator.

How do I use OR to set a specific bit?

Create a mask with only the target bit set to 1 and all others set to 0. For example, to set bit 3 (counting from 0 on the right), use the mask 8 (= 0000 1000 in binary). OR your value with this mask: result = value | 8. The target bit becomes 1 regardless of its previous state, and all other bits are unchanged.

What is the difference between logical OR and bitwise OR?

Logical OR (|| in most languages) treats each operand as a single true/false value and returns true if either is non-zero. Bitwise OR (|) operates on individual bits of both operands in parallel and returns a new integer. For single-bit values (0 or 1) the results agree, but for multi-bit integers they differ: 6 | 3 = 7 (bitwise), whereas 6 || 3 = true (logical).

Does OR work the same way in Python, JavaScript, C, and Java?

Yes for non-negative integers. All four languages use | for bitwise OR and apply the same bit-by-bit rule. The main practical difference is integer width: Python integers are arbitrary precision (no overflow), while C, Java, and JavaScript operate on fixed-width types (32-bit or 64-bit), which matters when high bits could overflow.

Sources

Written by Dr. Rajiv Menon, PhD Applied Mathematician · Bengaluru, India

Applied mathematician bridging algebraic theory and computational tools for students, engineers, and everyday problem-solvers.

Search 3,500+ calculators

Loading search…