🔢 OR Calculator
Perform bitwise OR operations on binary numbers
How to Use This Calculator
Enter Binary Numbers
Input two binary numbers in the input fields. The calculator accepts only 0s and 1s. Examples: 1010, 1100, 1111. OR returns 1 if either or both input bits are 1.
Click Calculate OR
Press the "Calculate OR" button to perform the bitwise OR operation. The calculator will automatically pad shorter numbers with leading zeros to match lengths.
Review Results
The result shows both the binary OR result and the decimal equivalent. OR returns 1 if at least one of the corresponding bits is 1, making it useful for combining flags or setting bits.
Formula
OR(A, B) = A | B
Bitwise OR: Result bit is 1 if either or both input bits are 1
How it works:
The OR operation compares each bit position of two binary numbers. If at least one bit is 1, the result is 1; only when both bits are 0 is the result 0. This makes OR useful for combining flags, setting bits, and logical unions.
OR Truth Table:
| A | B | A OR B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
Example 1: 1010 OR 1100
- Position 0: 0 OR 0 = 0
- Position 1: 1 OR 0 = 1
- Position 2: 0 OR 1 = 1
- Position 3: 1 OR 1 = 1
- Result: 1110 (binary) = 14 (decimal)
Example 2: 0101 OR 1010
- Position 0: 1 OR 0 = 1
- Position 1: 0 OR 1 = 1
- Position 2: 1 OR 0 = 1
- Position 3: 0 OR 1 = 1
- Result: 1111 (binary) = 15 (decimal)
Example 3: 0000 OR 1111
- All positions: 0 OR 1 = 1
- Result: 1111 (binary) = 15 (decimal)
Frequently Asked Questions
What is a bitwise OR operation?
A bitwise OR operation compares each bit of two binary numbers. The result is 1 if at least one of the corresponding bits is 1, and 0 only when both bits are 0. This is commonly used in programming for combining flags, setting bits, and logical unions.
What's the difference between logical OR (||) and bitwise OR (|)?
Logical OR (||) operates on boolean values and returns true/false. It uses short-circuit evaluation. Bitwise OR (|) operates on individual bits of numbers and returns a number. For example, 5 || 3 = true (both are truthy), but 5 | 3 = 7 (binary: 101 | 011 = 111).
When is OR operation used in programming?
OR operations are frequently used for: combining flags or permissions (e.g., READ | WRITE), setting specific bits in a number, checking if any of multiple conditions are true, implementing bitmasks, and in low-level systems programming for hardware control.
Can I use OR with decimal numbers?
Yes, but the calculator converts decimal numbers to binary first. The OR operation is performed bitwise, then converted back to decimal. Enter your decimal numbers, and the calculator will show both binary and decimal representations.
What happens if the binary numbers have different lengths?
The calculator automatically pads the shorter number with leading zeros to match the length of the longer number. For example, 101 OR 1100 becomes 0101 OR 1100, and the result is computed bit by bit.
How is OR used in flag systems?
OR is perfect for combining flags. For example, if READ = 1 (001), WRITE = 2 (010), and EXECUTE = 4 (100), you can combine them: READ | WRITE = 3 (011). This allows checking multiple permissions with a single bitwise operation. Checking if a permission is set uses AND: (flags & READ) != 0.