8.4 The OR operation
The OR operation (occasionally called the inclusive-OR operation to distinguish it more clearly from the exclusive-OR operation which I shall be introducing shortly) combines binary words bit by bit according to the rules:
0 OR 0 = 0
0 OR 1 = 1
1 OR 0 = 1
1 OR 1 = 1
In other words, the result is 1 when either bit is 1 or when both bits are 1; alternatively, the result is only 0 when both bits are 0. Again, you may prefer to think of it like this: when one bit is 1 or the other bit is 1 the result is 1.
Find the result of 1101 1011 OR 1011 1010.
The bits in the two words are combined according to the above rules, working along the two words. For instance, the rightmost bit of the result is derived from 1 OR 0 = 1. Doing this for all the bits gives:
so the result is 1111 1011.
The OR operation can be used to cause a particular bit in a data word to be set to 1 when required. Think back to the way a single 8-bit word could be used to hold the seven Boolean variables that represent whether the seven segments in a 7-segment display are lit, as introduced in Section 2.6. Imagine that for some purpose the decimal point needs to be lit no matter what number is currently being displayed. The bit corresponding to the decimal point on the display is bit 0, so if an OR operation is carried out between the 8-bit word currently holding the Boolean variables for the 7-segment display and
then the result will be to leave the leftmost seven bits unchanged but set bit 0 to 1, which will in turn cause the decimal point to light.