Connect via MCP →

Enter Calculation

Formula

Advertisement

Results

A | B (Bitwise OR)
14
decimal result
Operand A 12
Operand B 10
A | B 14

What is the Bitwise OR Calculator?

This calculator computes the bitwise OR of two integers, written in most programming languages as a | b. The OR operation compares the two numbers bit by bit and produces a result where each bit is 1 if either (or both) of the corresponding input bits is 1, and 0 only when both input bits are 0.

How to Use It

Enter your first integer (A) and your second integer (B), then read the decimal result. Both negative and positive whole numbers are supported. The tool works entirely in base 10 for input and output, but internally each value is treated as its binary representation.

The Formula Explained

The operation is performed per bit using the OR truth table: \(0|0=0\), \(0|1=1\), \(1|0=1\), \(1|1=1\). The general formula is:

$$\text{Result} = \text{A} \mathbin{|} \text{B}$$

For example, take A = 12 and B = 10. In binary, 12 = 1100 and 10 = 1010. Lining them up and OR-ing each column gives 1110, which equals 14 in decimal. So \(12 \mathbin{|} 10 = 14\).

Bitwise OR of two binary numbers shown column by column producing a result row
Bitwise OR compares each bit position: the result bit is 1 if either input bit is 1.

Worked Example

Suppose you want \(5 \mathbin{|} 3\). In binary, 5 = 101 and 3 = 011. OR-ing each bit: \(1|0=1\), \(0|1=1\), \(1|1=1\), giving 111 = 7. The calculator returns 7.

$$5 \mathbin{|} 3 = 7$$
Truth table grid for the OR operation of two single bits
OR truth table: the output is 0 only when both inputs are 0.

Common Bitwise OR Values Reference

The grid below gives \(A \mathbin{|} B\) for every pair of small operands from 0 to 8. Read the row for A and the column for B; the cell is the decimal result.

| 0 1 2 3 4 5 6 7 8
0 0 1 2 3 4 5 6 7 8
1 1 1 3 3 5 5 7 7 9
2 2 3 2 3 6 7 6 7 10
3 3 3 3 3 7 7 7 7 11
4 4 5 6 7 4 5 6 7 12
5 5 5 7 7 5 5 7 7 13
6 6 7 6 7 6 7 6 7 14
7 7 7 7 7 7 7 7 7 15
8 8 9 10 11 12 13 14 15 8

The diagonal (where A = B) always returns the operand itself, since x | x = x.

Bitwise OR is the standard way to combine permission flags. Common Unix-style permission bits are read = 4 (100), write = 2 (010), execute = 1 (001):

Combination Expression Decimal Binary
Read + Write 4 | 2 6 110
Read + Execute 4 | 1 5 101
Write + Execute 2 | 1 3 011
Read + Write + Execute (rwx) 4 | 2 | 1 7 111
Two bytes merged 240 | 15 255 11111111

Key Terms

Bit
The smallest unit of digital data, holding a single binary value of either 0 or 1. A group of 8 bits forms a byte.
Set / unset bit
A set bit has the value 1; an unset (or clear) bit has the value 0. Bitwise OR is commonly used to set specific bits without disturbing the others.
Bitmask
An integer whose bit pattern is chosen to select, set, or clear particular bits in another value. OR-ing a value with a mask forces every bit that is set in the mask to be set in the result.
Flag
An individual bit (often given a named constant) used to represent an on/off setting. Multiple flags are packed into one integer and combined with OR, e.g. READ | WRITE.
Two's complement
The standard way computers represent signed integers. The most significant bit carries negative weight, so an n-bit number ranges from \(-2^{n-1}\) to \(2^{n-1}-1\). For example, \(-1\) is stored as all 1-bits.
Most / least significant bit (MSB / LSB)
The MSB is the leftmost bit, carrying the largest place value (and the sign in two's complement); the LSB is the rightmost bit, with place value \(2^0 = 1\).
Base 10 vs base 2
Base 10 (decimal) is the everyday number system using digits 0–9. Base 2 (binary) uses only 0 and 1, with each position worth a power of two. Bitwise operations act on the base-2 representation, while this calculator displays the result in base 10.

FAQ

Is bitwise OR the same as addition? No. OR never carries. \(1|1\) stays 1, whereas \(1+1\) carries to 10 in binary. They only match when the operands share no overlapping set bits.

What about negative numbers? Negative integers use two's complement representation, so OR-ing them follows the same bit rules across the sign bits.

Why is OR useful? OR is commonly used to set (turn on) specific bits or combine flag values, such as merging permission masks.

Last updated: