cmsc 131 discussion 09-07-2011
TRANSCRIPT
![Page 1: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/1.jpg)
CMSC 131Object-Oriented Programming I
Instructor: Larry Herman
Section: 0302
Room: CSI 2118
![Page 2: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/2.jpg)
People to Know
• Instructor• Larry Herman• Email: [email protected]
•Teaching Assistant• Philip Dasler• Email: [email protected]
![Page 3: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/3.jpg)
Things I Lied About / Need to Clarify
• You must use Eclipse as provided on the class website.
• You can’t use laptops in lecture.
• Closer to 80 students in lectures.
• Recommended books are just that. Also, they are all the same.
• Office hours will be in A.V. Williams 1112
![Page 4: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/4.jpg)
More Administrivia
• Check for access to the grades server• grades.cs.umd.edu• Also, a link can be found on the class web page
• If you are officially registered for the course, you should have access.
• Grades server allows • View scores• View statistics• Report an absence
![Page 5: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/5.jpg)
Let’s Play a Game
What was covered in lecture?
![Page 6: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/6.jpg)
Let’s Play a Game
What was covered in lecture?• Parts of a computer• Bits, bytes, and words (0s and 1s)• N bits can represent 2N values• SI Prefixes (kilo, mega, kibibyte, mebi, etc.) ASCII
• Programming language types• machine code• assembly
![Page 7: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/7.jpg)
An Aside
Prefixes
1027 ??
1024 yotta1021 zetta1018 exa1015 peta1012 tera109 giga 106 mega103 kilo102 hecto101 deka
![Page 8: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/8.jpg)
An Aside
Prefixes
1027 hella
1024 yotta1021 zetta1018 exa1015 peta1012 tera109 giga 106 mega103 kilo102 hecto101 deka
![Page 9: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/9.jpg)
BASES
![Page 10: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/10.jpg)
Relearning How to Count
What number is this?
32,768
![Page 11: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/11.jpg)
Relearning How to Count
But how do you know?
32,768
![Page 12: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/12.jpg)
Relearning How to Count
32,768
Ones
Tens
Hundreds
Thousands
Ten Thousands
Positional Notation
![Page 13: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/13.jpg)
Relearning How to Count
8
60
700
2,000
+ 30,000
32,768
![Page 14: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/14.jpg)
Relearning How to Count
8 8 x 1
60 6 x 10
700 7 x 100
2,000 2 x 1000
+ 30,000 3 x 10000
32,768
![Page 15: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/15.jpg)
Relearning How to Count
8 8 x 100
60 6 x 101
700 7 x 102
2,000 2 x 103
+ 30,000 3 x 104
32,768
![Page 16: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/16.jpg)
Relearning How to Count
8 8 x 100
60 6 x 101
700 7 x 102
2,000 2 x 103
+ 30,000 3 x 104
32,768 Base 10(or radix 10)
![Page 17: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/17.jpg)
Other Bases
• Can be done with any base number.
• Numbers in Base N are made of the digits in the range 0 to N-1• Base 10 numbers are made up of 0, 1, 2, . . . 8, 9
• Examples• Base 3 numbers use 0, 1, and 2• Base 6 numbers use 0, 1, 2, 3, 4, and 5• Base 8 numbers use 0, 1, 2, 3, 4, 5, 6, and 7
![Page 18: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/18.jpg)
Other Bases - Example
• Notation: Xn means some number X in Base n
• Example:
Convert 13924 from Base 4 to Base 10.
![Page 19: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/19.jpg)
Other Bases - Example
2 2 x 40
36 9 x 41
48 3 x 42
+ 64 1 x 43
15010 Base 4
![Page 20: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/20.jpg)
Other Bases
• What is 2536 in Base 10?
![Page 21: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/21.jpg)
Other Bases
• What is 2536 in Base 10?
• 10510
![Page 22: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/22.jpg)
Other Bases
• What is 2536 in Base 10?
• 10510
• What is 1367 in Base 10?
![Page 23: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/23.jpg)
Other Bases
• What is 2536 in Base 10?
• 10510
• What is 1367 in Base 10?
• 7610
![Page 24: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/24.jpg)
Other Bases
• What is 2536 in Base 10?
• 10510
• What is 1367 in Base 10?
• 7610
• What is 4235 in Base 10?
![Page 25: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/25.jpg)
Other Bases
• What is 2536 in Base 10?
• 10510
• What is 1367 in Base 10?
• 7610
• What is 4235 in Base 10?
• 11310
![Page 26: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/26.jpg)
Going The Other Way
1. Do integer division by the base
2. Record the remainder as the next smallest place
3. Repeat on the result
Example: convert 7610 into Base 7
• 7610 divided by 7 gives 10 the remainder is 6 __6
• 1010 divided by 7 gives 1 the remainder is 3 _36
• 110 divided by 7 gives 0 the remainder is 1 136
7610 = 1367
![Page 27: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/27.jpg)
Going The Other Way
1. Do integer division by the base
2. Record the remainder as the next smallest place
3. Repeat on the result
Example: convert 11310 into Base 5
• 11310 divided by 5 gives 22 the remainder is 3 __3
• 2210 divided by 5 gives 4 the remainder is 2 _23
• 410 divided by 5 gives 0 the remainder is 4 423
11310 = 4235
![Page 28: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/28.jpg)
Reminder!
= ?
![Page 29: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/29.jpg)
Reminder!
= 0
0 with a remainder of 4
![Page 30: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/30.jpg)
Bringing It Back
So what does this have to do with computers?
Computers store everything as a series of 0s and 1s.
This is actually just regular numbers in Base 2!
What is 101010 in Base 10?
![Page 31: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/31.jpg)
Some Common Terms
•Base 2, Binary•Base 8, Octal•Base 10,Decimal•Base 16,Hexadecimal or Hex
These are the most common bases used in computing.
![Page 32: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/32.jpg)
Wait, Base 16?
But there aren’t enough numbers!
![Page 33: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/33.jpg)
Wait, Base 16?
But there aren’t enough numbers!
Hex uses the following digits:•0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F
•Thus, 4210 = 2A16
![Page 34: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/34.jpg)
Easy Conversions
We use binary, octal, and hex often because they are all powers of two.
This allows for easy conversions by just translating digits.
![Page 35: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/35.jpg)
Easy Conversions
Octal is Base 8
Binary is Base 2
8 is just 23
Thus, for every three digits in binary we can directly translate to a single octal digit.
![Page 36: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/36.jpg)
Easy Conversions
Example:Convert 758 to binary.
78 is 111 in binary.
58 is 101 in binary.
Thus, 758 = 1111012
![Page 37: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/37.jpg)
Easy Conversions
Works just as well for hex or backwards.
Convert 1011111101112 to hex.
10112 is B in hex.
11112 is F in hex.
01112 is 7 in hex.
Thus, 1011111101112 = BF716
![Page 38: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/38.jpg)
Easy Conversions
Decimal Binary Hex
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
Decimal Binary Hex
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
![Page 39: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/39.jpg)
Why Use Bases?• Computers store information in two states: “charged” or
“uncharged”
• These can easily be represented by 0s and 1s, making binary a convenient method for mathematical manipulation
• Hex is more compact and easily converts to and from binary
• 111111101110110111111010110011102 = FEEDFACE16
![Page 40: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/40.jpg)
QUESTIONS?
![Page 41: CMSC 131 Discussion 09-07-2011](https://reader035.vdocuments.mx/reader035/viewer/2022081506/55b88b10bb61ebf5558b46ed/html5/thumbnails/41.jpg)
Fun Stuff
1000111
1001111
1010100
1000101
1010010
1010000
1010011
Hint: In ASCII, the letter ‘A’ is represented by the number 65.
Individual digits
Hours Minutes Seconds
20
21
22
23