1320
play

1320 Principles Of Computer Science I Dr. Thomas Hicks Computer - PowerPoint PPT Presentation

1320 Principles Of Computer Science I Dr. Thomas Hicks Computer Science Department Trinity University 1 2 Decimal Numeration System Base 10 (Decimal) 3 4 Binary Numeration System Binary Convert Base 2 Base 10 5 147 Euler's


  1. 1320 Principles Of Computer Science I Dr. Thomas Hicks Computer Science Department Trinity University 1

  2. 2 Decimal Numeration System

  3. Base 10 (Decimal) 3

  4. 4 Binary Numeration System

  5. Binary  Convert Base 2  Base 10 5 147

  6. Euler's Process 6 10101111 175 (base 10) = (base 2)

  7. Euler Process (Verbal Description) 7

  8. Practical Usage 8

  9. 9 Octal Numeration System

  10. Octal  Base 8  Base 10 10 2073

  11. Euler's Process 11 257

  12. Convert Base 8  Base 2 12 10101111

  13. 13 Hexadecimal Numeration System

  14. Hexadecimal  Base 16  Base 10 14 267

  15. Convert Base 10  Base 16 15 10  a 11  b 12  c 13  d 14  e 15  f

  16. Convert Base 16  Base 2 16 10101111

  17. 17 Storage Of Positive Integers

  18. Physical Representation Of Byte In Memory 18 7 7 6 5 4 3 2 1 0 0 1 1 1 1 1 1 1  Byte – 8 bits   Bits Are Numbered!  High Bit  Called The Sign Bit  0  Positive Numbers  1  Negative Numbers  Biggest Positive Value (127?)  Sign Bit 0    All Other Digits 1

  19. Storage Of Positive Integers 19 7 6 5 4 3 2 1 0 0 1 1 1 1 1 1 1 1 *2 6 + 1 *2 5 + 1 *2 4 + 1 *2 3 + 1 *2 2 + 1 *2 1 + 1 *2 1 = 64 + 32 + 16 + 8 + 4 + 2 + 1 = 127

  20. 20 Strategy 1 For Storing Negative Numbers: Sign Magnitude

  21. 21 Sign Magnitude Storage Of Negative Integers 7 6 5 4 3 2 1 0 1 1 1 1 1 1 1 1 1 *2 6 + 1 *2 5 + 1 *2 4 + 1 *2 3 + 1 *2 2 + 1 *2 1 + 1 *2 0 = 64 + 32 + 16 + 8 + 4 + 2 + 1 = -127 1 1 1 1 1 1 1

  22. 22 Strategy 2 For Storing Negative Numbers: One’s Complement Negative Integers

  23. 23 One’s Complement Storage Of Negative Integers 7 6 5 4 3 2 1 0 1 0 0 0 0 0 0 0 -127 1 *2 6 + 1 *2 5 + 1 *2 4 + 1 *2 3 + 1 *2 2 + 1 *2 1 + 1 *2 0 = 64 + 32 + 16 + 8 + 4 + 2 + 1 = A  Take The Sign Magnitude 1 1 1 1 1 1 1 B  Invert The Digits 1  0 0  1 0 0 0 0 0 0 0

  24. 24 Strategy 3 For Storing Negative Numbers: Two’s Complement Negative Integers

  25. 25 Two’s Complement Storage Of Negative Integers Used By Almost All 7 6 5 4 3 2 1 0 Modern Day Computers 1 0 0 0 0 0 0 1 -127 1 *2 6 + 1 *2 5 + 1 *2 4 + 1 *2 3 + 1 *2 2 + 1 *2 1 + 1 *2 0 = 64 + 32 + 16 + 8 + 4 + 2 + 1 = A  Take The Sign Magnitude 1 1 1 1 1 1 1 B  Invert The Digits 1  0 0  1 0 0 0 0 0 0 0 C  Add 1 0 0 0 0 0 0 1

  26. 26 Short  Just Like Byte ( Except Bit 15 is Sign Bit )

  27. 2 Byte Short Integer Container 27 15 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0  Byte – 16 bits   High Bit  Called The Sign Bit  0  Positive Numbers  1  Negative Numbers  Biggest Positive Value (32,767)  Sign Bit 0    All Other Digits 1

  28. 28 Int  Just Like Byte ( Except Bit 31 is Sign Bit )

  29. 29 Long  Just Like Byte ( Except Bit 63 is Sign Bit )

  30. 30 Scala Conversion Functions

  31. 31 toBinaryString  toOctalString  toHexString  T  G

  32. 32 Byte Container

  33. 33 Binary Representation Of 50 in Byte Container 7 6 5 4 3 2 1 0 0 0 1 1 0 0 1 0 Quotient | Remainder 50 | ---------------------------------- 25 | 0 12 | 1 6 | 0 3 | 0 1 | 1 0 | 1

  34. 34 Binary Representation Of -50 in Byte Container Two’s Complement 7 6 5 4 3 2 1 0 1 1 0 0 1 1 1 0 Quotient | Remainder 50 | ---------------------------------- 25 | 0 12 | 1 0 0 1 1 0 0 1 0 6 | 0 3 | 0 1 1 0 0 1 1 0 1 1 | 1 0 | 1 1 1 1 0 0 1 1 1 0

  35. 35 Short Container

  36. 36 Binary Representation Of 160 in Int Container 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 Quotient | Remainder 160 | ---------------------------------- 80 | 0 40 | 0 20 | 0 10 | 0 5 | 0 2 | 1 1 | 0 0 | 1

  37. 37 Binary Representation Of -160 in Int Container Two’s Complement 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 0 Quotient | Remainder 160 | ---------------------------------- 80 | 0 40 | 0 20 | 0 10 | 0 5 | 0 2 | 1 1 | 0 0 | 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 0 0

  38. 38 Addition Of Base 2

  39. 39 Addition (Base 2) 1 1 1 0 1 1 0 1 1 0 0 1 1 0 1 + --------------------------------- 1

  40. 40 Addition (Base 2) 1 1 1 0 1 1 0 + 1 1 0 0 1 1 0 1 --------------------------------- 1 1

  41. 41 Addition (Base 2) 1 1 1 1 0 1 1 0 + 1 1 0 0 1 1 0 1 --------------------------------- 0 1 1

  42. 42 Addition (Base 2) 1 1 1 1 1 0 1 1 0 + 1 1 0 0 1 1 0 1 --------------------------------- 0 0 1 1

  43. 43 Addition (Base 2) 1 1 1 1 1 1 0 1 1 0 + 1 1 0 0 1 1 0 1 --------------------------------- 0 0 0 1 1

  44. 44 Addition (Base 2) 1 1 1 1 1 1 1 1 0 1 1 0 + 1 1 0 0 1 1 0 1 --------------------------------- 1 0 0 0 0 1 1

  45. 45 Addition (Base 2) 1 1 1 1 1 1 1 1 0 1 1 0 + 1 0 0 1 1 0 1 1 --------------------------------- 1 0 1 0 0 0 0 1 1

  46. 46 Addition (Base 2) 1 1 1 0 1 1 0 + 1 0 0 1 1 0 1 1 --------------------------------- 1 0 1 0 0 0 0 1 1

  47. 47 Convert To Base 10 118 1 1 1 0 1 1 0 = ______________ (base 10) 64 + 32 + 16 + 4 + 2

  48. 48 Convert To Base 10 205 1 1 0 0 1 1 0 1 = ______________ (base 10) + + + 128 64 8 + 4 1

  49. 49 Convert To Base 10 323 1 0 1 0 0 0 0 1 1 = __________ (base 10) 256 + 64 + 2 + 1

  50. 50 Addition (Base 2) 1 1 1 0 1 1 0 118 + 1 0 0 1 1 0 1 1 205 -------- --------------------------------- 323 1 0 1 0 0 0 0 1 1

  51. 51 Subtraction Of Base 2

  52. 52 Subtraction (Base 2) 1 1 0 0 1 1 0 1 1 - --------------------- 0

  53. 53 Subtraction (Base 2) 1 1 0 0 1 1 0 1 1 - -------------------- 0

  54. 54 Subtraction (Base 2) 0 2 1 1 0 0 1 x x 1 0 1 1 - -------------------- 0

  55. 55 Subtraction (Base 2) 1 2 0 2 x 1 1 0 0 1 x x x 1 0 1 1 - -------------------- 1 0

  56. 56 Subtraction (Base 2) 1 0 2 2 x 1 1 0 0 1 x x x 1 0 1 1 - -------------------- 1 1 0

  57. 57 Subtraction (Base 2) 1 2 0 2 2 x x 1 1 0 0 1 x x x x 1 0 1 1 - -------------------- 1 1 1 0

  58. 58 Subtraction (Base 2) 1 1 0 0 1 1 0 1 1 - -------------------- 1 1 1 0

  59. 59 Convert To Base 10 25 1 1 0 0 1 = ______________ (base 10) 16 + 8 + 1

  60. 60 Convert To Base 10 11 1 0 1 1 = ______________ (base 10) 8 2 1 + +

  61. 61 Convert To Base 10 1 1 1 0 14 = ______________ (base 10) 8 + 4 + 2

  62. 62 Subtraction (Base 2) 25 1 1 0 0 1 11 1 0 1 1 - ----- -------------------- 14 1 1 1 0

  63. 63 By Default, All Mathematics Is Done With Int & Double!

  64. 64 Decision To Optimize Speed We Will Use Mostly Int  Today’s applications store all single Byte & Short in a 32/64 bit chunk of main memory for calculation efficiency!

  65. 65 Decision To Optimize Speed We Will Use Mostly Double

  66. 66 Why Should A Computer Scientist Know How Data Is Stored On Disk?

  67. 67 Why?  I could say that you need to learn it because it will be used in  Computer Architecture  Operating Systems  Compiler Construction

  68. 68 Byte 7 6 5 4 3 2 1 0 0 1 1 1 1 1 1 0 7 6 5 4 3 2 1 0 0 1 1 1 1 1 1 1 7 6 5 4 3 2 1 0 1 0 0 0 0 0 0 0

  69. 69 Int

  70. 70 Principles Of Programming I CSCI 1320 Dr. Thomas E. Hicks Computer Science Department Trinity University Textbook: An Introduction to Programming with Scala By Dr. Mark Lewis Special Thanks To Dr. Mark Lewis For Providing Some Of Text For Use In This Presentation.

Recommend


More recommend