Section 6.8
Bitwise Logical Operations

Most computers provide machine instructions to perform AND, OR and NOT on strings of bits. The Boolean operations are applied independently to each bit, which is why they are called bitwise. Below are some examples using 8-bit registers. The C operators for bitwise AND (&), bitwise OR (|) and bitwise NOT (^) are employed.
   10011100     1011100    1011100
 & 01101010   | 0110101   ^
-----------   ---------   --------
   00001000     1111101    0100011

Oftentimes these bitwise operations are used for data manipulation tasks that are only remotely connected to logic. AND is often used as a mask or filter, only allowing bits whose positions are 1s in the other operand to be viewed. OR is often used as a collector of bits to combine several different data bits into one mask. NOT is used to compute the 1's complement.

Performing the OR of a string of bits is harder. One could logically shift the value and OR together all of the bits as they pass through the MSB, which is the N bit. Another way is to simply ask if the decimal value of the bit string is 0. If it is then there are no 1s anywhere in it. If it is not 0, then there is at least one 1. AND of a string of bits is similar. If the string is -1 (all 1s) in 2's complement then the AND of this string is 1. But if it is any other value, the AND is 0, since there is at least one 0.