OR Calculator

Compute the bitwise OR of two whole numbers, bit by bit: see the result in decimal, binary, and hexadecimal, plus how many bits are set in the result.

Quick Facts

Rule
Each result bit is 1 when at least one input bit is 1
OR compares A and B one binary digit at a time.
Identity
A OR 0 = A; A OR (all 1s) = all 1s
ORing with 0 leaves bits unchanged; ORing with a mask of 1s sets them.

Your Results

Calculated
A OR B
-
Decimal result
Binary result
-
Zero-padded to bit width
Hexadecimal result
-
Base-16 representation
Set bits in result
-
Bit positions where either input is 1

Ready

Enter two whole numbers and a bit width, then press Calculate.

How the OR Calculator works

This tool computes the bitwise OR of two whole numbers. Bitwise OR compares two numbers one binary digit (bit) at a time: the result has a 1 in a given position if either number has a 1 in that same position, and a 0 only when both numbers have a 0 there. It is one of the four fundamental logic operations in computing, alongside AND, XOR, and NOT.

Formula and method

For each bit position, the result bit follows a simple rule: result = 1 when A or B (or both) has a 1 in that position; the result bit is 0 only when both are 0. That gives the single-bit truth table 0 OR 0 = 0, 0 OR 1 = 1, 1 OR 0 = 1, 1 OR 1 = 1. To compute A OR B for whole numbers, write both numbers in binary padded to the same length, then apply this rule to every column independently. For example, 12 (1100 in binary) OR 10 (1010 in binary) gives 1110 in binary, which is 14 in decimal — a column produces a 1 whenever at least one of the two numbers had a 1 there.

Common sources of error

  • Bit width too small: a number that does not fit the selected bit width is rejected rather than silently truncated — choose 16-bit or 32-bit for larger values.
  • Confusing OR with AND: OR only requires one bit to be 1; AND requires both. Swapping them produces the wrong mask when setting versus clearing bits.
  • Misreading bit order: bit 0 is the rightmost (least significant) bit, not the leftmost, in standard binary notation.

Checking your result

A quick sanity check: A OR B can never be smaller than the larger of A and B, because OR only ever sets bits — it never clears a bit that was already 1 in either operand. If a computed result is less than max(A, B), something is wrong. You can also verify small examples by hand: write both numbers in binary, align the columns, and OR each column individually.

Applications

Bitwise OR is used throughout computing: turning on specific flag or permission bits without disturbing others, merging two sets of binary options into one value, combining color or pixel data, computing a broadcast address from a network address and the inverse of a subnet mask, and building a bitmask by ORing together individual bit values.

Frequently Asked Questions

What does bitwise OR do?
Bitwise OR compares two numbers bit by bit. Each bit in the result is 1 if at least one of the matching bits in the two numbers is 1, and 0 only when both matching bits are 0.
How is bitwise OR different from logical OR?
Logical OR (||) combines two true/false values and returns a single boolean. Bitwise OR (|) operates on the binary digits of numbers and returns a number, comparing every bit position independently.
How is OR used to set flags or bits in a bitmask?
ORing a value with a mask turns on every bit position where the mask has a 1, leaving other bits unchanged. This is the standard way to set individual flags or permission bits without disturbing the rest of a value.
Can this calculator handle negative numbers?
This tool treats both inputs as non-negative integers represented in plain binary up to the selected bit width (8, 16, or 32 bits). Negative numbers require two's complement representation, which is outside the scope of this calculator.