Binary OR Operation
OR linking the bits of two integers
Bitwise OR Calculator
Bitwise OR Operation
This function performs a binary OR operation on the bits of two integers. The result bit is 1 when at least one of the input bits is 1.
OR Operation Visualization
Example: 8 OR 4 = 12
OR Truth Table
OR Properties
- Result is 0 only when both bits are 0
- Result is 1 when at least one bit is 1
- Commutative: A | B = B | A
- Associative: (A | B) | C = A | (B | C)
Mathematical Foundations of Bitwise OR Operation
The bitwise OR operation is applied bitwise to the corresponding positions:
Mathematical Definition
For each bit position i, logical disjunction is applied
Bitwise Application
Simultaneous OR operation on all corresponding bit pairs
OR Operation Formulas and Examples
General OR Formula
Bitwise OR operation of two binary numbers A and B
Step-by-Step Example: 8 OR 4
1st Number A: 8₁₀ = 1000₂
2nd Number B: 4₁₀ = 0100₂
Position: 3210 (from right)
OR Operation:
Position 3: 1 | 0 = 1
Position 2: 0 | 1 = 1
Position 1: 0 | 0 = 0
Position 0: 0 | 0 = 0
Result: 1100₂ = 12₁₀ = C₁₆
More OR Examples
A: 00001111₂ (15)
B: 11110000₂ (240)
Result: 11111111₂ (255)
A: 00000111₂ (7)
B: 00111000₂ (56)
Result: 00111111₂ (63)
Mathematical Properties of OR Operation
\[A \lor B = B \lor A\]
Order of operands is arbitrary
\[(A \lor B) \lor C = A \lor (B \lor C)\]
Parentheses are arbitrary
\[A \lor 0 = A\]
OR with 0 changes nothing
\[A \lor A = A\]
OR with itself = original
OR Reference
Standard Example
OR Truth Table
Bitwise Operators
|: bitwise OR
&: bitwise AND
^: bitwise XOR
~: bitwise NOT
<<,>>: bit shift
Common Applications
Set bits: x | mask
Activate flags: status | flag
Combine masks: mask1 | mask2
Enable register: reg | enable
Bitwise OR Operation - Detailed Description
OR Operation Fundamentals
The bitwise OR is applied to the bit sequences of two integers. The bits at the same position are linked with a logical OR (logical disjunction). The respective result bit is 0 only if both bits are 0.
• 0 | 0 = 0 (both bits are 0)
• 0 | 1 = 1 (at least one bit is 1)
• 1 | 0 = 1 (at least one bit is 1)
• 1 | 1 = 1 (both bits are 1)
Processing Logic
When one or both bits are 1, the result bit is set to 1. The OR operation is particularly useful for setting specific bits or combining bit patterns.
Processing Steps
1. Convert both numbers to binary representation
2. Process bit by bit from right to left
3. Apply OR operation to corresponding bit pairs
4. Convert result to desired format
Practical Applications
Bitwise OR operations are fundamental in digital logic and computer programming. They enable targeted bit setting, flag combination, and implementation of logical circuits.
• Bit masks for flags and status
• Hardware register manipulation
• Logic circuits
• Data compression and filtering
Mathematical Properties
The OR operation follows important mathematical laws such as commutativity and associativity, making it a powerful tool in Boolean algebra.
Important Properties
- Commutative: A | B = B | A
- Associative: (A | B) | C = A | (B | C)
- Identity element: A | 0 = A
- Idempotent: A | A = A
Practical OR Operation Examples
Flag Combination
Scenario: Combine permissions
Read Flag: 100₂ (4)
Write Flag: 010₂ (2)
Result: 110₂ (6 = Read+Write)
Hardware Register
Scenario: LED control
Current: 10100000₂
New LEDs: 00001100₂
Result: 10101100₂
Bit Masks
Scenario: Data filtering
Data: 11010010₂
Mask: 00001111₂
Result: 11011111₂
Programming Tips
- Flag constants: #define FLAG_A (1<<0)
- Set multiple flags: flags |= (FLAG_A | FLAG_B)
- Combine bit fields: result = field1 | field2
- Check status: if (status & FLAG)
- Apply masks: data |= mask
- Performance: Bitwise ops are very fast
|