CMSC 131 Discussion 09-07-2011
Transcript of CMSC 131 Discussion 09-07-2011
CMSC 131Object-Oriented Programming I
Instructor: Larry Herman
Section: 0302
Room: CSI 2118
People to Know
• Instructor• Larry Herman• Email: [email protected]
•Teaching Assistant• Philip Dasler• Email: [email protected]
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
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
Let’s Play a Game
What was covered in lecture?
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
An Aside
Prefixes
1027 ??
1024 yotta1021 zetta1018 exa1015 peta1012 tera109 giga 106 mega103 kilo102 hecto101 deka
An Aside
Prefixes
1027 hella
1024 yotta1021 zetta1018 exa1015 peta1012 tera109 giga 106 mega103 kilo102 hecto101 deka
BASES
Relearning How to Count
What number is this?
32,768
Relearning How to Count
But how do you know?
32,768
Relearning How to Count
32,768
Ones
Tens
Hundreds
Thousands
Ten Thousands
Positional Notation
Relearning How to Count
8
60
700
2,000
+ 30,000
32,768
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
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
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)
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
Other Bases - Example
• Notation: Xn means some number X in Base n
• Example:
Convert 13924 from Base 4 to Base 10.
Other Bases - Example
2 2 x 40
36 9 x 41
48 3 x 42
+ 64 1 x 43
15010 Base 4
Other Bases
• What is 2536 in Base 10?
Other Bases
• What is 2536 in Base 10?
• 10510
Other Bases
• What is 2536 in Base 10?
• 10510
• What is 1367 in Base 10?
Other Bases
• What is 2536 in Base 10?
• 10510
• What is 1367 in Base 10?
• 7610
Other Bases
• What is 2536 in Base 10?
• 10510
• What is 1367 in Base 10?
• 7610
• What is 4235 in Base 10?
Other Bases
• What is 2536 in Base 10?
• 10510
• What is 1367 in Base 10?
• 7610
• What is 4235 in Base 10?
• 11310
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
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
Reminder!
= ?
Reminder!
= 0
0 with a remainder of 4
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?
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.
Wait, Base 16?
But there aren’t enough numbers!
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
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.
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.
Easy Conversions
Example:Convert 758 to binary.
78 is 111 in binary.
58 is 101 in binary.
Thus, 758 = 1111012
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
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
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
QUESTIONS?
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