1 / 23

Bits, Data types, and Operations: Chapter 2

1. Bits, Data types, and Operations: Chapter 2. COMP 2610. Dr. James Money COMP 2610. Operations on Bits. So far, we have seen we can perform addition and subtraction on binary patterns Recall the meaning of ALU – arithmetic and logic unit The other set of operations is logical operations.

kiona-burke
Télécharger la présentation

Bits, Data types, and Operations: Chapter 2

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. 1 Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP 2610

  2. Operations on Bits • So far, we have seen we can perform addition and subtraction on binary patterns • Recall the meaning of ALU – arithmetic and logic unit • The other set of operations is logical operations

  3. Operations on Bits • Recall that the name logical is historical in origin • It refers to the fact that a bit has two values 0 and 1 • These refer to false and true, respectively • We consider several basic logical functions of the ALU

  4. AND Function • AND is a binary logical function • It takes two source operands, and produces one result • Each source is a logical values, either 0 or 1 • The output of AND is 1 only if both the source values are 1 • Otherwise the output is 0

  5. AND Function • A convenient way to represent the behavior of logical operation is the truth table • A truth table has n+1 columns and 2nrows • The n columns refer to the source operands and the +1 refers to the output • Each value has two possible values, so there are 2n choices

  6. AND Function

  7. AND Function

  8. AND Function • We can also apply the AND operation to two bits patterns of m bits each • We apply the AND function to each pair of bits in the two source operands • This operation is called a bitwise AND

  9. AND Function • IF c=a AND b where a=0011101001101001 and b=0101100100100001, what is c? a: 0011101001101001 b: 0101100100100001 c: 0001100000100001

  10. AND Function • Suppose we have an 8 bit pattern called A in which only the two right-most bits are significant • The computer will do one of four tasks depending on the value of these two bits • How do we isolate these two bits?

  11. AND Function • We can use a bitmask to get this value • The bitmask should be 1 for the bits you are interested in and 0 elsewhere • So we would use the bitmask 00000011 • Then we apply the A AND bitmask

  12. AND Function • If A=01010110, A: 01010110 Bitmask: 00000011 00000010 • If A=11111100, A: 11111100 Bitmask: 00000011 00000000

  13. OR Function • OR is also a binary logical function • It requires two source operand and produces one output • The output of OR is only 0 if both inputs are 0 • Otherwise, it is 1 • We can apply the OR operation to m bits the same as the AND function

  14. OR Function

  15. OR Function

  16. OR Function • Some times this is called the inclusive-OR function to differentiate it from the exclusive OR operator • Let a=0011101001101001 and b=0101100100100001 • What is c=a OR b?

  17. OR Function a: 0011101001101001 b: 0101100100100001 c: 0111101101101001

  18. NOT Function • NOT is a unary logical function • That is, it only takes one source operand, and outputs one result • This is also known as the complement operation • We says the output is formed by inverting the bits

  19. NOT Function

  20. NOT Function • We can apply the NOT function to a single m bit pattern the same way we apply it to two m bit patterns for AND and OR • Let c=NOT a and a=0011101001101001 a: 0011101001101001 c: 1100010110010110

  21. XOR Function • The Exclusive-OR or XOR function is a binary logical function with two source operands and one result • The output of XOR is 1 two sources are different • Otherwise, the output is 0 • We can apply this to m bit patterns as well

  22. XOR Function

  23. XOR Function • Let a=0011101001101001, b=01011001001000001, and find c=a XOR b a: 0011101001101001 b: 0101100100100001 c: 0110001101001000 • We can use XOR to determine if two bit patterns are identical!

More Related