Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept...

87
mith College Computer Science Dominique Thiébaut [email protected] Lecture Notes CSC111 Week 3 — Sept 21, 2015

Transcript of Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept...

Page 1: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

mith College

Computer Science

Dominique Thiébaut [email protected]

Lecture Notes CSC111

Week 3 — Sept 21, 2015

Page 2: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Chapter 3 in Zelle

Page 3: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Finish Exercise from last week

(printing bar graph)…

Page 4: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

Midterm Exam: Friday Oct. 16th

In class, 1 hour 10 min

On paper

Closed books

Closed notes

Closed computers

Page 5: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

When computers were human, a talk by David Grier: start at 28m12s, for 4 minutes.

http://youtu.be/YwqltwvPnkw?t=28m12s

Page 6: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Arithmetic operators and math functions

Printing numbers to look "nice"

Using a main() function

Accumulating results

What are bits?

Page 7: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Arithmetic OperatorsOperator Name Result

+ sum float if 1 side is float, else int

- subtraction float if 1 side is float, else int

* multiplication float if 1 side is float, else int

/ real division float

// integer division int

% modulo int

** exponentiation float if 1 side is float, else int

Page 8: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Demo Time!

Page 9: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Exercise: Writing a Teller Machine

Program

Page 10: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

How much money do you want to withdraw?

Page 11: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

How much money do you want to withdraw? 139

Page 12: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

How much money do you want to withdraw? 139

Please find the following bills below: 6 $20-bill(s) 1 $10-bill(s) 1 $5-bill(s) 4 $1-bill(s)

Page 13: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Programming Time!

Page 14: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Arithmetic operators and math functions

Printing numbers to look "nice"

Using a main() function

Accumulating results

What are bits?

Page 15: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name: Alex age: 12 coefficient: 6.18888888 /20 name: Anastasia age: 22 coefficient: 8 /20

Current output

Page 16: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name: Alex age: 12 coefficient: 6.18888888 /20 name: Anastasia age: 22 coefficient: 8 /20

Current output

String IntFloat

Page 17: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name: Alex age: 12 coefficient: 6.18888888 /20 name: Anastasia age: 22 coefficient: 8 /20

name: Alex age: 12 coefficient: 6.19/20 name: Anastasia age: 22 coefficient: 8.00/20

Current output

Wanted output

(See Section 5.8.2 in Zelle)

Page 18: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name = "Alex" "name: {0:10}X" . format( name )

Page 19: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name = "Alex" “name: {0:10}X" . format( name )

'name: X' 1234567890

Page 20: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name = "Alex" 0th "name: {0:10}X" . format( name )

'name: X' 1234567890

'name: Alex X' 1234567890

Page 21: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name = "Alex" "name: {0:10}X" . format( name )

'name: X' 1234567890

'name: Alex X' 123456789

'name: Alex X'

Page 22: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name1 = "Alex" name2 = "Anastasia""names: {0:10}X{1:10}Y" . format( name1, name2 )

Page 23: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name1 = "Alex" name2 = "Anastasia""names: {0:10}X{1:10}Y" . format( name1, name2 )

"names: X Y" 1234567890 1234567890

Page 24: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name1 = "Alex" name2 = "Anastasia" 0 1"names: {0:10}X{1:10}Y" . format( name1, name2 )

"names: X Y" 1234567890 1234567890

"names: Alex XAnastasia Y" 1234567890 1234567890

Page 25: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name1 = "Alex" name2 = "Anastasia" 0 1"names: {0:10}X{1:10}Y" . format( name1, name2 )

"names: X Y" 1234567890 1234567890

"names: Alex XAnastasia Y" 1234567890 1234567890

"names: Alex XAnastasia Y"

Page 26: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name1 = "Alex" name2 = "Anastasia" 0 1"names: {0:10}X{1:10}Y" . format( name1, name2 )

"names: X Y" 1234567890 1234567890

"names: Alex XAnastasia Y" 1234567890 1234567890

"names: Alex XAnastasia Y"

What about right-justification?

Page 27: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

We stopped here last time…

Page 28: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name1 = "Alex" name2 = "Anastasia" 0 1"names: {0:>10}X{1:>10}Y". format( name1, name2 )

"names: X Y" 1234567890 1234567890

"names: AlexX AnastasiaY" 1234567890 1234567890

"names: AlexX AnastasiaY"

Page 29: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Bar Graph Exercise (revisited)

First name? DominiqueLast name? ThiebautId? 990123456Final grade? 90

+———————————————————————————————————-———————————-+|Dominique Thiebaut 990123456 |+———————————————————————————————————-———————————-+ 00...10...20...30...40...50...60...70...80...90...100grade: #############################################class: ########################################

Page 30: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

It works the same for integers!

Page 31: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name1 = "Alex" age = 22 0 1"name: {0:10} age: {1:3}!". format( name1, age )

"name: age: !" 1234567890 123

"name: Alex age: 22!" 1234567890 123

"name: Alex age: 22!"

Ints areautomaticallyright-aligned

Page 32: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name1 = "Alex" age = 22 0 1"name: {0:10} age: {1:<3}!". format( name1, age )

"name: age: !" 1234567890 123

"name: Alex age: 22 !" 1234567890 123

"name: Alex age: 22 !"

Use '<' to left-align

Page 33: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Floats are a bit different… We need to specify

a total number of digits, and a number of digits after the decimal point.

Page 34: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Pi = 3.141592653589793

"Pi ={0:10.2f}#" . format( Pi )

"Pi = #" 1234567890

Page 35: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Pi = 3.141592653589793

"Pi ={0:10.2f}#" . format( Pi )

"Pi = #" 1234567890 12

"Pi = 3.14#" 1234567890 12

Page 36: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

We can left- and right-alignfloats with '<' and '>' as well…

Page 37: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

name1 = "Alex"age1 = 12coef1 = 6.188888name2 = "Anastasia"age2 = 22coef2 = 8

print( ??? .format( name1, age1, coef1 ) )print( ??? .format( name2, age2, coef2 ) )

name: Alex age: 12 coefficient: 6.19/20name: Anastasia age: 22 coefficient: 8.00/20 1234567890 123 123456 12

Page 38: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Arithmetic operators and math functions

Printing numbers to look "nice"

Using a main() function

Accumulating results

What are bits?

Page 39: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

print( "Hello world!" )print( "Welcome to CSC111!" )

def main():print( "Hello world!" )print( "Welcome to CSC111" )

main()

Page 40: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

def main():print( "Hello world!" )print( "Welcome to CSC111" )

main()

Hello world! Welcome to CSC111

Read

Execute

Page 41: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

def main():print( "Hello world!" )print( "Welcome to CSC111" )

main()main()

Hello world! Welcome to CSC111 Hello world! Welcome to CSC111

Read

ExecuteExecute

Page 42: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Function Syntax

def <name> ( <parameters> ): <body>

Page 43: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Demo Time!

Page 44: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Arithmetic operators and math functions

Printing numbers to look "nice"

Using a main() function

Accumulating results

What are bits?

Page 45: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Compute the Sum of Several Numbers.

ages = [12, 14, 10]

sumAge = ?

Page 46: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Compute the Sum of Several Numbers.

ages = [12, 14, 10]

sumAge = ?

# review printing all elements of a listfor age in [12, 14, 10]:

print( age )

12 14 10

Page 47: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Compute the Sum of Several Numbers.

ages = [12, 14, 10]

sumAge = ?

# review printing all elements of a listfor age in [12, 14, 10]:

print( age )

12 14 10

0 <— sumAge 0+12 = 12 <— sumAge 12+14 = 26 <— sumAge 26+10 = 36 <— sumAge

<—Algorithm for sum

Page 48: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Compute the Sum of Several Numbers.

ages = [12, 14, 10]

sumAge = 0

# review printing all elements of a listfor age in [12, 14, 10]:

#print( age )sumAge = sumAge + age

0 <— sumAge 0+12 = 12 <— sumAge 12+14 = 26 <— sumAge 26+10 = 36 <— sumAge

<— new code

Page 49: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Compute the Sum of Several Numbers.

ages = [12, 14, 10]

sumAge = 0

# review printing all elements of a listfor age in [12, 14, 10]:

#print( age )sumAge = sumAge + age

print( "sum = ", sumAge )

sum = 36

Page 50: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

ExercisesCompute is the sum of all the integers between 1 and 10

Compute is the sum of all the multiples of 6 between 0 and 100,included

Compute is the sum of all the integers between 1 and 1000

Page 51: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

More Exercises

Using the same approach, write a loop that creates a string of special characters, defined by a list of values: Example: [ 3, 2, 1, 5] would result in "###++#+++++"

[1,2,1,3,4] would result in "#++#+###++++"

Compute is the factorial of 5 (factorial of 5 = 5 x 4 x 3 x 2 x 1)

Page 52: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Arithmetic operators and math functions

Printing numbers to look "nice"

Using a main() function

Accumulating results

What are bits?

Page 53: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

MATH

Number Systems 0 1 2 3 4 5 6 7 8 9 10

Page 54: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

MATH

Number Systems 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 10 1010

Page 55: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

MATH

Number Systems 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 10 1010

BOOLEANLOGIC

True False AND

OR NOT

Page 56: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

MATH

Number Systems 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 10 1010

BOOLEANLOGIC

True False AND

OR NOT

Claude Shannon

Page 57: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

MATH

Number Systems 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 10 1010

BOOLEANLOGIC

True False AND

OR NOT

Claude Shannon

ENGINEERING

Page 58: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

MATH

Number Systems 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 10 1010

BOOLEANLOGIC

True False AND

OR NOT

Claude Shannon

ENGINEERING

Page 59: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

MATH

Number Systems 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 10 1010

BOOLEANLOGIC

True False AND

OR NOT

Claude Shannon

ENGINEERING

COMPUTERS

Page 60: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND

OR

NOT

Page 61: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND

OR

NOT

True

False

False

Page 62: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND

OR

NOT

True

True

True

Page 63: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND

OR

NOT

False

TrueTrue

Page 64: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND

OR

NOTFalseTrue

Page 65: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND

OR

NOT

01

0

11

0

10

Page 66: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND

OR

NOT

01

0

11

0

10

Can be built with a few transistors

Can use electricityto represent 0 and 1

Page 67: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND NOT

NOT AND

1

1

001

1

1 0

Page 68: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND NOT

NOT AND

1

1

001

1

1 0 0

Page 69: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND NOT

NOT AND

1

1

001

1

1 0 00

Page 70: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND NOT

NOT AND

1

1

001

1

1 0 000

Page 71: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND NOT

NOT AND

1

1

001

1

1 0 000 1

Page 72: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND NOT

NOT AND

1

1

01

1

1 0 100 1

0 1

Page 73: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND NOT

NOT AND

1

1

01

1

1 0 100 1

0 11

Page 74: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND NOT

NOT AND

1

1

01

1

1 0 100 1

0 110

Page 75: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND NOT

NOT AND

1

1

01

1

1 0 100 1

0 110

0

Page 76: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND NOT

NOT AND

1

110 1

110

0

Page 77: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

AND NOT

NOT AND

1

110 1

110

0

Page 78: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Page 79: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

• A bit is a device that stores either 1 or 0

Page 80: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

• A bit is a device that stores either 1 or 0

• By extension, a bit is either 1 or 0

Page 81: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

• A bit is a device that stores either 1 or 0

• By extension, a bit is either 1 or 0

• A bit is a unit of information

Page 82: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

• A bit is a device that stores either 1 or 0

• By extension, a bit is either 1 or 0

• A bit is a unit of information

• 2 bits take on 1 of 4 states: 00, 01, 10, 11

Page 83: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

• A bit is a device that stores either 1 or 0

• By extension, a bit is either 1 or 0

• A bit is a unit of information

• 2 bits take on 1 of 4 states: 00, 01, 10, 11

• 3 bits: 000, 001, 010, 011, 100, 101, 110, 111

Page 84: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

• A bit is a device that stores either 1 or 0

• By extension, a bit is either 1 or 0

• A bit is a unit of information

• 2 bits take on 1 of 4 states: 00, 01, 10, 11

• 3 bits: 000, 001, 010, 011, 100, 101, 110, 111

• 8 bits = 1 byte00000000, 00000001, … to 11111111 256 possible combinations of 0s and 1s

Page 85: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

Page 86: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

https://www.youtube.com/watch?v=xaTywFdZrOk

Page 87: Lecture Notes CSC111 - Clark Science Center · 2015-09-21 · Lecture Notes CSC111 Week 3 — Sept 21, 2015. D. Thiebaut, Computer Science, Smith College Chapter 3 in Zelle. D. Thiebaut,

D. Thiebaut, Computer Science, Smith College

A 01000001

0110 1001 1001 1111 1001 1001

10001000 01101010 00001000RED GREEN BLUE

Character

Pixel