Logical and Shift operations A particular bit, or set of bits, within the byte is set to 1 or 0 depending on conditions encountered during the execution of a program. When so used, these bits are often called "flags". Frequently, the programmer must manipulate these individual bits - an activity sometimes known as "bit twiddling". The logical and shift operations provide the means for manipulating the bits.
Logical operations OR Operations OR Results in 1 if either or both of the operands are 1. OR Table 0 OR 0 = 0 0 OR 1 = 1 1 OR 0 = 1 1 OR 1 = 1
Logical operations To perform the OR operation, take one column at a time and perform the OR operation using the OR table. Ex 1: OR
Logical operations Ex 2: OR Ex 3: 0111 OR
Logical operations XOR Operations The exclusive OR. Similar to OR except that it gives 0 when both its operands are 1. Rules. 0 XOR 0 = 0 0 XOR 1 = 1 1 XOR 0 = 1 1 XOR 1 = 0
Logical operations Ex 1: XOR Ex 2: 0111 XOR
Logical operations NOT Operations NOT is a separate operator for flipping all bits. Rules. NOT 0 = 1 NOT 1 = 0 Example.NOT
Logical operations AND Operations AND yields 1 only if both its operands are 1. Rules. 0 AND 0 = 0 0 AND 1 = 0 1 AND 0 = 0 1 AND 1 = 1
Logical operations Ex 1: AND Ex 2: 0111 AND
Shift and Rotate operations Where as logical operations allow the changing of bit values in place, shift and rotate operations allow bits to be moved left or right without changing their values.
Shift and Rotate operations SHL SHL (shift left) shifts each bit one place to the left. The original leftmost bit is lost and a 0 is shifted into the rightmost position. Ex 1.SHL Ex 2.SHL
Shift and Rotate operations SHR SHR (shift right) shifts each bit one place to the right. The original rightmost bit is lost and a 0 is shifted into the leftmost position. Ex 1.SHR Ex 2.SHR
Shift and Rotate operations ROL ROL (rotate left) shifts each bit one place to the left. The original leftmost bit is shifted into the rightmost position. No bits are lost. Ex 1.ROL ROL
Shift and Rotate operations ROR ROR (rotate right) shifts each bit one place to the right. The original rightmost bit is shifted into the leftmost position. No bits are lost. Ex 1.ROR Ex 2.ROR