1 / 14

Logical and Shift operations

Logical and Shift operations.

Download Presentation

Logical and Shift operations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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.

  2. 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

  3. Logical operations To perform the OR operation, take one column at a time and perform the OR operation using the OR table. Ex 1: 10010011 OR 00001111 10011111

  4. Logical operations Ex 2: 11001001 OR 00001010 11001011 Ex 3: 0111 OR 0010 0111

  5. 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

  6. Logical operations • Ex 1: 10011001 XOR 00001111 10010110 Ex 2: 0111 XOR 0010 0101

  7. Logical operations NOT Operations • NOT is a separate operator for flipping all bits. Rules. NOT 0 = 1 NOT 1 = 0   Example. NOT 1010 0101

  8. 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

  9. Logical operations  Ex 1: 11010011 AND 00001111 00000011   Ex 2: 0111 AND 1001 0001

  10. 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.

  11. 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 1101 1 1010 Ex 2. SHL 1100 1000

  12. 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 1011 0101 1 Ex 2. SHR 0011 0001

  13. 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 1101 1011 ROL 1100 1001

  14. 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 1011 1101 Ex 2. ROR 0011 1001

More Related