In digital electronics and software, we often meet the OR function, also known as the inclusive OR. The logic symbols for an electronic OR gate are as follows:
The truth table for OR is as follows:
In words, the output is 1 is either or both inputs are a 1. Some observations about this:
- If you OR a bit ‘A’ with a 1, then the result is always a 1 (set)
- If you OR a bit ‘A’ with a 0, then the result is A (preserved)
We use these properties to set or preserve individual or groups of bits
This is not limited to single bits. In software, we often perform logical operations on integers (binary numbers). Consider the following example:
The OR function is applied to each pair of bits. In the C or C++ programming language, this could be calculated as:
unsigned A = 162; //A2 IN HEX A = A | 15;
The result is 175 //AF IN HEX