Содержание
- 2. After reading this chapter, the reader should be able to: OBJECTIVES
- 3. Figure 4-1 Operations on bits
- 4. ARITHMETIC OPERATIONS 4.1
- 5. Arithmetic operations Arithmetic operations involve: Adding (+) Subtracting (--) Multiplying (X) Dividing (/) And so on…
- 6. Table 4.1 Adding bits Number of 1s ------------ None One Two Three Result ------------ 0 1
- 7. Rule of Adding Integers in Two’s Complement Add 2 bits and propagate the carry to the
- 8. Example 1 Add two numbers in two’s complement representation: (+17) + (+22) ? (+39) Solution Carry
- 9. Example 2 Add two numbers in two’s complement representation: (+24) + (-17) ? (+7) Solution Carry
- 10. Example 3 Add two numbers in two’s complement representation: (-35) + (+20) ? (-15) Solution Carry
- 11. Example 4 Add two numbers in two’s complement representation: (+127) + (+3) ? (+130) Solution Carry
- 12. Range of numbers in two’s complement representation - (2N-1) ---------- 0 ----------- +(2N-1 –1) Note:
- 13. Figure 4-2 Two’s complement numbers visualization
- 14. When you do arithmetic operations on numbers in a computer, remember that each number and the
- 15. Example 5 Subtract 62 from 101 in two’s complement: (+101) - (+62) ?? (+101) + (-62)
- 16. Arithmetic operations on floating-point numbers Addition and subtraction for floating-point numbers are one process. (p. 54)
- 17. Example 6 Add two floats: 0 10000100 10110000000000000000000 0 10000010 01100000000000000000000 Solution The exponents are 5
- 18. LOGICAL OPERATIONS 4.2
- 19. Logical operations A logical operation can accept 1 or 2 bits to create only 1 bit.
- 20. Figure 4-3 Unary and binary operations
- 21. Figure 4-4 Logical operations
- 22. Figure 4-5 Truth tables
- 23. Figure 4-6 Unary operator -- NOT operator
- 24. Example 7 Use the NOT operator on the bit pattern 10011000 Solution Target 1 0 0
- 25. Figure 4-7 Binary operator--AND operator
- 26. Example 8 Use the AND operator on bit patterns 10011000 and 00110101. Solution Target 1 0
- 27. Figure 4-8 Inherent (本質的) rule of the AND operator
- 28. Figure 4-9 Binary operator--OR operator
- 29. Example 9 Use the OR operator on bit patterns 10011000 and 00110101 Solution Target 1 0
- 30. Figure 4-10 Inherent rule of the OR operator
- 31. Figure 4-11 Binary operator--XOR operator
- 32. Example 10 Use the XOR operator on bit patterns 10011000 and 00110101. Solution Target 1 0
- 33. Figure 4-12 Inherent rule of the XOR operator
- 34. Figure 4-13 Mask (遮罩) Applications
- 35. Figure 4-14 Example of unsetting specific bits
- 36. Example 11 Use a mask to unset (clear) the 5 leftmost bits of a pattern. Test
- 37. Example 12 Imagine a power plant (水力發電廠) that pumps water (供水) to a city using eight
- 38. Use the mask 10111111 to AND with the target pattern. The only 0 bit (bit 7)
- 39. Figure 4-15 Example of setting specific bits
- 40. Example 13 Use a mask to set the 5 leftmost bits of a pattern. Test the
- 41. Example 14 Using the power plant example, how can you use a mask to to show
- 42. Figure 4-16 Example of flipping (跳動的) specific bits
- 43. Example 15 Use a mask to flip the 5 leftmost bits of a pattern. Test the
- 44. SHIFT OPERATIONS 4.3
- 45. Figure 4-17 Shift operations Right shift Left shift
- 46. Solution If a bit pattern represents an unsigned number, a right-shift operation divides the number by
- 47. Example 17 Use the mask 00001000 to AND with the target to keep the fourth bit
- 48. Solution (continued) Target a b c d e f g h AND Mask 0 0 0
- 50. Скачать презентацию