Computer Science 15-100 (APEA Section E), Summer 2009
Class Notes: Introduction
Logistics
- First Day
- Welcome and Introductions
- Syllabus + Course Policies
- Reading:
- L&L Chapter 1 (Introduction)
- L&L Appendix B (Number Systems)
- L&L Appendix C (Unicode)
- Hw1: due tomorrow!
- Practice Quiz0: on Wednesday
- Quiz1 (real!) on Thursday: Covers Chapter 1 (read it
carefully!!!)
Topic Outline:
- College 101
- 10 * 16 / 6 ~= 27, and Why This Matters
- How to Read the Textbook
- Programming vs Computer Science
- The Digital in "Digital Computers"
- Represent everything as numbers
- Letters as numbers (Unicode: 'A' = 65, 'a' = 97, '0' = 48, 'space'
= 32)
- Pictures as numbers (pixels -> RGB)
- Sounds as numbers (see p 6; sampling rate, digitization, etc)
- Represent numbers in binary (base 2)
- Represent binary in physical transistors
- Thus: everything is a 1 or 0 (hence, digital)
- Analog vs. Digital
- Powers of 2
- 28 = 256 [ eg: IP addresses contain numbers
between 0 and 255; same often goes for RGB values... ]
- 210 =~ 1k
- 220 =~ 1m
- 230 =~ 1b
- So: 231 = 2*230 =~ 2b
- And: 232 = 22*230 =~ 4b
- Counting in Base 2, Base 10, and Base 16
- Converting between bases
- Two's Complement (or: How to represent negative numbers in
binary)
- Negate by flipping the bits (complementing) and adding one
- For example (in 4-bit two's complement):
To compute -6:
Start with +6 = 0110
Flip the bits: 1001
And add 1: 1010
= -6 Let's confirm this by
negating the negation:
Start with -6 = 1010
Flip the bits: 0101
And add 1: 0110
= +6 (It works!)
- Q: What does 1111 equal? How about 11111111...1111?
- Neat trick (and why we do this): subtraction by addition:
- For example (in 4-bit two's complement):
To add -6 and +7:
-6 = 1010
+7 = 0111
----
0001 = +1 (It
works!)
To add -6 and +3:
-6 = 1010
+3 = 0011
----
1101 = -3
(flip the bits --> 0010, add 1 --> 0011 = +3).
- So what?
Well, given that Java represents integers in 32-bit two's complement:
- The largest positive integer is (231 - 1) or about 2
billion.
- If we add one to that number, we get 231, which is the
smallest negative, or about negative 2 billion.
- Let's rephrase that:
If we start a counter in Java at 0 and keep adding 1 to it, soon after 2
billion we'll overflow and the counter will equal about -2 billion!
Wow!
- Some Units You Should Know
- Bit, Nybble, Byte
- Kilobit (Kb), Kilobyte (KB), Megabit (Mb), Megabyte (MB), Gigabit (Gb),
Gigabyte (GB), Terabit (Tb), Terabyte (TB)
- Hertz (Hz)
- Kilohertz (KHz) and millisecond (ms), Megahertz (MHz) and microsecond
(mu-s), Gigahertz (GHz) and nanosecond (ns)
- Note: Light travels about 1 foot in one billionth of a second (one
nanosecond)
- Note: Modems are 56 Kbps and not 56 KBps!
- Moore's Law:
- Roughly: for the same price, every 2 years computers are twice as
fast with twice the RAM, twice the storage, etc...
(or so said Intel co-founder Gordon Moore in 1965; he's been right for 44
years and counting!)
- See http://en.wikipedia.org/wiki/Moore's_law.
Q: About how much faster will computers be in 10 years? 20
years? Roughly when will computers be 1 million times faster than
today?
- Your Personal HashCode
- Given an ordered list of n integers, L = [ dn-1, dn-2,
..., d1, d0 ], define
hash<P,E>(L) = П(Pkdk)
% 10E
So, for example:
hash<31,4>(L) = П(31kdk)
% 104
= 31n-1dn-1 · 31n-2dn-2
· ... · 31d1
· d0.
= d0.+ (31 · (d1 +
31 · (d2 + 31
· ( ... + 31 · (dn-2,
+ 31dn-1)
- For an integer, set di to the decimal digits, so:
hash<31,4>(4973) = hash<31,4>([4, 9, 7,
3])
= (313·4 + 312·9 +31·7 + 3) % 104
= (128033 % 104)
= 8033
- For a String (an ordered list of
characters), such as an andrewId, set di to the Unicode values,
so:
hash<31,4>("koz") = hash<31,4>([107,
111, 122])
= (312·107 + 31·111 + 122) % 104
= (106390 % 104)
= 6390
- Unless otherwise noted, we will assume your
personal hashcode is hash<31,4>(your andrew id).
carpe diem -
carpe diem - carpe diem - carpe diem
- carpe diem - carpe diem -
carpe diem - carpe diem - carpe
diem