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

1320
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1
  • Dr. Thomas Hicks

Computer Science Department Trinity University

1

1320

Principles Of Computer Science I

slide-2
SLIDE 2

Decimal Numeration System

2

slide-3
SLIDE 3

Base 10 (Decimal)

3

slide-4
SLIDE 4

Binary Numeration System

4

slide-5
SLIDE 5

Binary  Convert Base 2  Base 10

5

147

slide-6
SLIDE 6

Euler's Process

6

175 (base 10) = (base 2)

10101111

slide-7
SLIDE 7

Euler Process (Verbal Description)

7

slide-8
SLIDE 8

Practical Usage

8

slide-9
SLIDE 9

Octal Numeration System

9

slide-10
SLIDE 10

Octal  Base 8  Base 10

10

2073

slide-11
SLIDE 11

Euler's Process

11

257

slide-12
SLIDE 12

Convert Base 8  Base 2

12

10101111

slide-13
SLIDE 13

Hexadecimal Numeration System

13

slide-14
SLIDE 14

Hexadecimal  Base 16  Base 10

14

267

slide-15
SLIDE 15

Convert Base 10  Base 16

15

10  a 11  b 12  c 13  d 14  e 15  f

slide-16
SLIDE 16

Convert Base 16  Base 2

16

10101111

slide-17
SLIDE 17

Storage Of Positive Integers

17

slide-18
SLIDE 18

Physical Representation Of Byte In Memory

 Byte – 8 bits

18

1 2 3 4 5 6 7

 Bits Are Numbered!

7

 High Bit  Called The Sign Bit

 0  Positive Numbers  1  Negative Numbers

 Biggest Positive Value (127?)

  Sign Bit 0

  All Other Digits 1 1 1 1 1 1 1 1

slide-19
SLIDE 19

Storage Of Positive Integers

19

1 1 1 1 1 1 1

1*26 + 1*25 + 1*24 + 1*23 + 1*22 + 1*21 + 1*21 =

1 2 3 4 5 6 7

64 + 32 + 16 + 8 + 4 + 2 + 1 = 127

slide-20
SLIDE 20

Strategy 1 For Storing Negative Numbers:

Sign Magnitude

20

slide-21
SLIDE 21

Sign Magnitude Storage Of Negative Integers

21 1*26 + 1*25 + 1*24 + 1*23 + 1*22 + 1*21 + 1*20 =

1 2 3 4 5 6 7

64 + 32 + 16 + 8 + 4 + 2 + 1 = -127

1 1 1 1 1 1 1 1

1 1 1 1 1 1 1

slide-22
SLIDE 22

Strategy 2 For Storing Negative Numbers:

One’s Complement Negative Integers

22

slide-23
SLIDE 23

One’s Complement Storage Of Negative Integers

23 1*26 + 1*25 + 1*24 + 1*23 + 1*22 + 1*21 + 1*20 =

1 2 3 4 5 6 7

64 + 32 + 16 + 8 + 4 + 2 + 1 =

1

  • 127

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

slide-24
SLIDE 24

Strategy 3 For Storing Negative Numbers:

Two’s Complement Negative Integers

24

slide-25
SLIDE 25

Two’s Complement Storage Of Negative Integers

25 1*26 + 1*25 + 1*24 + 1*23 + 1*22 + 1*21 + 1*20 =

1 2 3 4 5 6 7

64 + 32 + 16 + 8 + 4 + 2 + 1 =

1 1

  • 127

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

Used By Almost All Modern Day Computers

slide-26
SLIDE 26

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

26

slide-27
SLIDE 27

2 Byte Short Integer Container

27

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

 Byte – 16 bits

15

 High Bit  Called The Sign Bit

 0  Positive Numbers  1  Negative Numbers

 Biggest Positive Value (32,767)

  Sign Bit 0

  All Other Digits 1

slide-28
SLIDE 28

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

28

slide-29
SLIDE 29

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

29

slide-30
SLIDE 30

Scala Conversion Functions

30

slide-31
SLIDE 31

toBinaryString  toOctalString  toHexString

 T  G

31

slide-32
SLIDE 32

Byte Container

32

slide-33
SLIDE 33

Binary Representation Of 50 in Byte Container

33

1 2 3 4 5 6 7

1 1 1

Quotient | Remainder 50 |

  • 25 | 0

12 | 1 6 | 0 3 | 0 1 | 1 0 | 1

slide-34
SLIDE 34

Binary Representation Of -50 in Byte Container Two’s Complement

34

1 2 3 4 5 6 7

1 1 1 1 1

Quotient | Remainder 50 |

  • 25 | 0

12 | 1 6 | 0 3 | 0 1 | 1 0 | 1

1 1 1 1 1 1 1 1 1 1 1 1 1 1

slide-35
SLIDE 35

Short Container

35

slide-36
SLIDE 36

Binary Representation Of 160 in Int Container

36

Quotient | Remainder 160 |

  • 80 | 0

40 | 0 20 | 0 10 | 0 5 | 0 2 | 1 1 | 0 0 | 1

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1 1

slide-37
SLIDE 37

Binary Representation Of -160 in Int Container Two’s Complement

37

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Quotient | Remainder 160 |

  • 80 | 0

40 | 0 20 | 0 10 | 0 5 | 0 2 | 1 1 | 0 0 | 1

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

slide-38
SLIDE 38

Addition Of Base 2

38

slide-39
SLIDE 39

Addition (Base 2)

39

1 1 1 1 1 1 1 1 1 1

  • 1

+

slide-40
SLIDE 40

Addition (Base 2)

40

  • 1

1 + 1 1 1 1 1 1 1 1 1 1

slide-41
SLIDE 41

Addition (Base 2)

41

  • 1

1 + 1 1 1 1 1 1 1 1 1 1 1

slide-42
SLIDE 42

Addition (Base 2)

42

  • 1

1 + 1 1 1 1 1 1 1 1 1 1 1 1

slide-43
SLIDE 43

Addition (Base 2)

43

  • 1

1 + 1 1 1 1 1 1 1 1 1 1 1 1 1

slide-44
SLIDE 44

Addition (Base 2)

44

  • 1

1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

slide-45
SLIDE 45

Addition (Base 2)

45

  • 1

1 1 + 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

slide-46
SLIDE 46

Addition (Base 2)

46

  • 1

1 1 + 1 1 1 1 1 1 1 1 1 1 1

slide-47
SLIDE 47

Convert To Base 10

47

1 1 1 1 1

2 4 16 32 64

= ______________ (base 10)

+ + + +

118

slide-48
SLIDE 48

Convert To Base 10

48

= ______________ (base 10)

+ + + +

205 1 1 1 1 1

1 4 128 64 8

slide-49
SLIDE 49

Convert To Base 10

49

= __________ (base 10) 323 1 1 1 1

2 256 1 64 + + +

slide-50
SLIDE 50

Addition (Base 2)

50

  • 1

1 1 + 1 1 1 1 1 1 1 1 1 1 1 323 205 118

slide-51
SLIDE 51

Subtraction Of Base 2

51

slide-52
SLIDE 52

Subtraction (Base 2)

52

1 1 1 1 1 1

slide-53
SLIDE 53

Subtraction (Base 2)

53

1 1 1 1 1 1

slide-54
SLIDE 54

Subtraction (Base 2)

54

1 1 1 1 1 1

  • 2

x x

slide-55
SLIDE 55

Subtraction (Base 2)

55

1 1 1 1 1 1

  • 2

x x x

1 2

x

1

slide-56
SLIDE 56

Subtraction (Base 2)

56

1 1 1 1 1 1

  • 2

x x x

1 2

x

1 1

slide-57
SLIDE 57

Subtraction (Base 2)

57

1 1 1 1 1 1

  • 2

x x x

1 2

x

1 1

x

2

x

1

slide-58
SLIDE 58

Subtraction (Base 2)

58

1 1 1

  • 1

1 1

  • 1

1 1

slide-59
SLIDE 59

Convert To Base 10

59

1 16 8

= ______________ (base 10)

+ +

25 1 1 1

slide-60
SLIDE 60

Convert To Base 10

60

1 8 2

= ______________ (base 10)

+ +

11 1 1 1

slide-61
SLIDE 61

Convert To Base 10

61

2 8 4

= ______________ (base 10)

+ +

14 1 1 1

slide-62
SLIDE 62

Subtraction (Base 2)

62

1 1 1

  • 1

1 1

  • 1

1 1 25 11

  • 14
slide-63
SLIDE 63

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

63

slide-64
SLIDE 64

Today’s applications store all single Byte & Short in a 32/64

bit chunk of main memory for calculation efficiency!

Decision To Optimize Speed We Will Use Mostly Int

64

slide-65
SLIDE 65

Decision To Optimize Speed We Will Use Mostly Double

65

slide-66
SLIDE 66

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

66

slide-67
SLIDE 67

I could say that you need to learn it because it will be used

in

Computer Architecture Operating Systems Compiler Construction

Why?

67

slide-68
SLIDE 68

Byte

68

1 2 3 4 5 6 7

1 1 1 1 1 1

1 2 3 4 5 6 7

1 1 1 1 1 1 1

1 2 3 4 5 6 7

1

slide-69
SLIDE 69

Int

69

slide-70
SLIDE 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. 70