csci 127: introduction to computer science...i list: a sequence of items e.g. [3, 1, 4, 5, 9] or...

235
CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 11 28 April 2020 1 / 47

Upload: others

Post on 18-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

CSci 127: Introduction to Computer Science

hunter.cuny.edu/csci

CSci 127 (Hunter) Lecture 11 28 April 2020 1 / 47

Page 2: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected] Discussion Board: on Blackboard, link

on purple menu barI Drop-in tutoring (12pm-5pm):

sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 11 28 April 2020 2 / 47

Page 3: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected] Discussion Board: on Blackboard, link

on purple menu barI Drop-in tutoring (12pm-5pm):

sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 11 28 April 2020 2 / 47

Page 4: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected]

I Discussion Board: on Blackboard, linkon purple menu bar

I Drop-in tutoring (12pm-5pm):sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 11 28 April 2020 2 / 47

Page 5: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected] Discussion Board: on Blackboard, link

on purple menu bar

I Drop-in tutoring (12pm-5pm):sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 11 28 April 2020 2 / 47

Page 6: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected] Discussion Board: on Blackboard, link

on purple menu barI Drop-in tutoring (12pm-5pm):

sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 11 28 April 2020 2 / 47

Page 7: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Announcements

Please always read all Blackboardannouncements

Online help is available in multiple forms whenschool is in session:

I Email: [email protected] Discussion Board: on Blackboard, link

on purple menu barI Drop-in tutoring (12pm-5pm):

sign in here:https://bit.ly/csci127Tutoringthen join the session here:https://bit.ly/csci127TutoringSession

CSci 127 (Hunter) Lecture 11 28 April 2020 2 / 47

Page 8: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Today’s Topics

Design Patterns: Searching

Python Recap

Machine Language

Machine Language: Jumps & Loops

Binary & Hex Arithmetic

Final Exam: Format

CSci 127 (Hunter) Lecture 11 28 April 2020 3 / 47

Page 9: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Today’s Topics

Design Patterns: Searching

Python Recap

Machine Language

Machine Language: Jumps & Loops

Binary & Hex Arithmetic

Final Exam: Format

CSci 127 (Hunter) Lecture 11 28 April 2020 4 / 47

Page 10: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Predict what the code will do:

CSci 127 (Hunter) Lecture 11 28 April 2020 5 / 47

Page 11: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Python Tutor

(Demo with pythonTutor)

CSci 127 (Hunter) Lecture 11 28 April 2020 6 / 47

Page 12: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Pattern: Linear Search

Example of linear search.

Start at the beginning of the list.

Look at each item, one-by-one.

Stopping, when found, or the end oflist is reached.

CSci 127 (Hunter) Lecture 11 28 April 2020 7 / 47

Page 13: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Pattern: Linear Search

Example of linear search.

Start at the beginning of the list.

Look at each item, one-by-one.

Stopping, when found, or the end oflist is reached.

CSci 127 (Hunter) Lecture 11 28 April 2020 7 / 47

Page 14: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Pattern: Linear Search

Example of linear search.

Start at the beginning of the list.

Look at each item, one-by-one.

Stopping, when found, or the end oflist is reached.

CSci 127 (Hunter) Lecture 11 28 April 2020 7 / 47

Page 15: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Pattern: Linear Search

Example of linear search.

Start at the beginning of the list.

Look at each item, one-by-one.

Stopping, when found, or the end oflist is reached.

CSci 127 (Hunter) Lecture 11 28 April 2020 7 / 47

Page 16: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Today’s Topics

Design Patterns: Searching

Python Recap

Machine Language

Machine Language: Jumps & Loops

Binary & Hex Arithmetic

Final Exam: Format

CSci 127 (Hunter) Lecture 11 28 April 2020 8 / 47

Page 17: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Python & Circuits Review: 10 Weeks in 10 Minutes

A whirlwind tour of the semester, so far...

CSci 127 (Hunter) Lecture 11 28 April 2020 9 / 47

Page 18: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 1: print(), loops, comments, & turtles

Introduced comments & print():

#Name: Thomas Hunter ← These lines are comments

#Date: September 1, 2017 ← (for us, not computer to read)

#This program prints: Hello, World! ← (this one also)

print("Hello, World!") ← Prints the string ”Hello, World!” to the screen

As well as definite loops & the turtle package:

CSci 127 (Hunter) Lecture 11 28 April 2020 10 / 47

Page 19: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 1: print(), loops, comments, & turtles

Introduced comments & print():

#Name: Thomas Hunter ← These lines are comments

#Date: September 1, 2017 ← (for us, not computer to read)

#This program prints: Hello, World! ← (this one also)

print("Hello, World!") ← Prints the string ”Hello, World!” to the screen

As well as definite loops & the turtle package:

CSci 127 (Hunter) Lecture 11 28 April 2020 10 / 47

Page 20: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 1: print(), loops, comments, & turtles

Introduced comments & print():

#Name: Thomas Hunter ← These lines are comments

#Date: September 1, 2017 ← (for us, not computer to read)

#This program prints: Hello, World! ← (this one also)

print("Hello, World!") ← Prints the string ”Hello, World!” to the screen

As well as definite loops & the turtle package:

CSci 127 (Hunter) Lecture 11 28 April 2020 10 / 47

Page 21: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 2: variables, data types, more on loops & range()

A variable is a reserved memory location for storing a value.Different kinds, or types, of values need different amounts of space:

I int: integer or whole numbersI float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’]I class variables: for complex objects, like turtles.

More on loops & ranges:

CSci 127 (Hunter) Lecture 11 28 April 2020 11 / 47

Page 22: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 2: variables, data types, more on loops & range()A variable is a reserved memory location for storing a value.

Different kinds, or types, of values need different amounts of space:I int: integer or whole numbersI float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’]I class variables: for complex objects, like turtles.

More on loops & ranges:

CSci 127 (Hunter) Lecture 11 28 April 2020 11 / 47

Page 23: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 2: variables, data types, more on loops & range()A variable is a reserved memory location for storing a value.Different kinds, or types, of values need different amounts of space:

I int: integer or whole numbers

I float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’]I class variables: for complex objects, like turtles.

More on loops & ranges:

CSci 127 (Hunter) Lecture 11 28 April 2020 11 / 47

Page 24: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 2: variables, data types, more on loops & range()A variable is a reserved memory location for storing a value.Different kinds, or types, of values need different amounts of space:

I int: integer or whole numbersI float: floating point or real numbers

I string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’]I class variables: for complex objects, like turtles.

More on loops & ranges:

CSci 127 (Hunter) Lecture 11 28 April 2020 11 / 47

Page 25: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 2: variables, data types, more on loops & range()A variable is a reserved memory location for storing a value.Different kinds, or types, of values need different amounts of space:

I int: integer or whole numbersI float: floating point or real numbersI string: sequence of characters

I list: a sequence of itemse.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’]

I class variables: for complex objects, like turtles.

More on loops & ranges:

CSci 127 (Hunter) Lecture 11 28 April 2020 11 / 47

Page 26: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 2: variables, data types, more on loops & range()A variable is a reserved memory location for storing a value.Different kinds, or types, of values need different amounts of space:

I int: integer or whole numbersI float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’]I class variables: for complex objects, like turtles.

More on loops & ranges:

CSci 127 (Hunter) Lecture 11 28 April 2020 11 / 47

Page 27: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 2: variables, data types, more on loops & range()A variable is a reserved memory location for storing a value.Different kinds, or types, of values need different amounts of space:

I int: integer or whole numbersI float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’]

I class variables: for complex objects, like turtles.

More on loops & ranges:

CSci 127 (Hunter) Lecture 11 28 April 2020 11 / 47

Page 28: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 2: variables, data types, more on loops & range()A variable is a reserved memory location for storing a value.Different kinds, or types, of values need different amounts of space:

I int: integer or whole numbersI float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’]I class variables: for complex objects, like turtles.

More on loops & ranges:

CSci 127 (Hunter) Lecture 11 28 April 2020 11 / 47

Page 29: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 2: variables, data types, more on loops & range()A variable is a reserved memory location for storing a value.Different kinds, or types, of values need different amounts of space:

I int: integer or whole numbersI float: floating point or real numbersI string: sequence of charactersI list: a sequence of items

e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’]I class variables: for complex objects, like turtles.

More on loops & ranges:

CSci 127 (Hunter) Lecture 11 28 April 2020 11 / 47

Page 30: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 3: colors, hex, slices, numpy & images

CSci 127 (Hunter) Lecture 11 28 April 2020 12 / 47

Page 31: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 3: colors, hex, slices, numpy & images

CSci 127 (Hunter) Lecture 11 28 April 2020 12 / 47

Page 32: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 3: colors, hex, slices, numpy & images

CSci 127 (Hunter) Lecture 11 28 April 2020 12 / 47

Page 33: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 4: design problem (cropping images) & decisions

First: specify inputs/outputs. Input file name, output file name,upper, lower, left, right (“bounding box”)

Next: write pseudocode.1 Import numpy and pyplot.2 Ask user for file names and dimensions for cropping.3 Save input file to an array.4 Copy the cropped portion to a new array.5 Save the new array to the output file.

Next: translate to Python.

CSci 127 (Hunter) Lecture 11 28 April 2020 13 / 47

Page 34: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 4: design problem (cropping images) & decisions

First: specify inputs/outputs. Input file name, output file name,upper, lower, left, right (“bounding box”)

Next: write pseudocode.1 Import numpy and pyplot.2 Ask user for file names and dimensions for cropping.3 Save input file to an array.4 Copy the cropped portion to a new array.5 Save the new array to the output file.

Next: translate to Python.

CSci 127 (Hunter) Lecture 11 28 April 2020 13 / 47

Page 35: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 4: design problem (cropping images) & decisions

First: specify inputs/outputs. Input file name, output file name,upper, lower, left, right (“bounding box”)

Next: write pseudocode.1 Import numpy and pyplot.2 Ask user for file names and dimensions for cropping.3 Save input file to an array.4 Copy the cropped portion to a new array.5 Save the new array to the output file.

Next: translate to Python.

CSci 127 (Hunter) Lecture 11 28 April 2020 13 / 47

Page 36: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 4: design problem (cropping images) & decisions

First: specify inputs/outputs. Input file name, output file name,upper, lower, left, right (“bounding box”)

Next: write pseudocode.1 Import numpy and pyplot.2 Ask user for file names and dimensions for cropping.3 Save input file to an array.4 Copy the cropped portion to a new array.5 Save the new array to the output file.

Next: translate to Python.

CSci 127 (Hunter) Lecture 11 28 April 2020 13 / 47

Page 37: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 4: design problem (cropping images) & decisions

CSci 127 (Hunter) Lecture 11 28 April 2020 14 / 47

Page 38: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 5: logical operators, truth tables & logical circuits

in1 in2 returns:

False and False FalseFalse and True FalseTrue and False FalseTrue and True True

CSci 127 (Hunter) Lecture 11 28 April 2020 15 / 47

Page 39: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 5: logical operators, truth tables & logical circuits

in1 in2 returns:

False and False FalseFalse and True FalseTrue and False FalseTrue and True True

CSci 127 (Hunter) Lecture 11 28 April 2020 15 / 47

Page 40: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 6: structured data, pandas, & more design

nycHistPop.csv

In Lab 6

import matplotlib.pyplot as plt

import pandas as pd

pop = pd.read csv(’nycHistPop.csv’,skiprows=5)

pop.plot(x="Year")

plt.show()

CSci 127 (Hunter) Lecture 11 28 April 2020 16 / 47

Page 41: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 6: structured data, pandas, & more design

nycHistPop.csv

In Lab 6

import matplotlib.pyplot as plt

import pandas as pd

pop = pd.read csv(’nycHistPop.csv’,skiprows=5)

pop.plot(x="Year")

plt.show()

CSci 127 (Hunter) Lecture 11 28 April 2020 16 / 47

Page 42: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 6: structured data, pandas, & more design

nycHistPop.csv

In Lab 6

import matplotlib.pyplot as plt

import pandas as pd

pop = pd.read csv(’nycHistPop.csv’,skiprows=5)

pop.plot(x="Year")

plt.show()

CSci 127 (Hunter) Lecture 11 28 April 2020 16 / 47

Page 43: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 6: structured data, pandas, & more design

nycHistPop.csv

In Lab 6

import matplotlib.pyplot as plt

import pandas as pd

pop = pd.read csv(’nycHistPop.csv’,skiprows=5)

pop.plot(x="Year")

plt.show()

CSci 127 (Hunter) Lecture 11 28 April 2020 16 / 47

Page 44: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 6: structured data, pandas, & more design

nycHistPop.csv

In Lab 6

import matplotlib.pyplot as plt

import pandas as pd

pop = pd.read csv(’nycHistPop.csv’,skiprows=5)

pop.plot(x="Year")

plt.show()

CSci 127 (Hunter) Lecture 11 28 April 2020 16 / 47

Page 45: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 7: functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 11 28 April 2020 17 / 47

Page 46: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 7: functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 11 28 April 2020 17 / 47

Page 47: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 7: functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 11 28 April 2020 17 / 47

Page 48: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 7: functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:

Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 11 28 April 2020 17 / 47

Page 49: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 7: functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 11 28 April 2020 17 / 47

Page 50: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 7: functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,

which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 11 28 April 2020 17 / 47

Page 51: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 7: functions

Functions are a way to break code into pieces,that can be easily reused.

Many languages require that all code must beorganized with functions.

The opening function is often called main()

You call or invoke a function by typing its name,followed by any inputs, surrounded by parenthesis:Example: print("Hello", "World")

Can write, or define your own functions,which are stored, until invoked or called.

CSci 127 (Hunter) Lecture 11 28 April 2020 17 / 47

Page 52: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 8: function parameters, github

Functions can have inputparameters.

Surrounded by parenthesis, bothin the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 11 28 April 2020 18 / 47

Page 53: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 8: function parameters, github

Functions can have inputparameters.

Surrounded by parenthesis, bothin the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 11 28 April 2020 18 / 47

Page 54: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 8: function parameters, github

Functions can have inputparameters.

Surrounded by parenthesis, bothin the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 11 28 April 2020 18 / 47

Page 55: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 8: function parameters, github

Functions can have inputparameters.

Surrounded by parenthesis, bothin the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 11 28 April 2020 18 / 47

Page 56: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 8: function parameters, github

Functions can have inputparameters.

Surrounded by parenthesis, bothin the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 11 28 April 2020 18 / 47

Page 57: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 8: function parameters, github

Functions can have inputparameters.

Surrounded by parenthesis, bothin the function definition,and in the function call(invocation).

The “placeholders” in thefunction definition: formalparameters.

The ones in the function call:actual parameters.

Functions can also returnvalues to where it was called.

CSci 127 (Hunter) Lecture 11 28 April 2020 19 / 47

Page 58: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 9: top-down design, folium, loops, and random()

CSci 127 (Hunter) Lecture 11 28 April 2020 20 / 47

Page 59: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 10: more on loops, max design pattern, random()

Indefinite (while) loops allow you torepeat a block of code as long as acondition holds.

Very useful for checking user inputfor correctness.

Python’s built-in random packagehas useful methods for generatingrandom whole numbers and realnumbers.

To use, must include:import random.

The max design pattern provides atemplate for finding maximum valuefrom a list.

CSci 127 (Hunter) Lecture 11 28 April 2020 21 / 47

Page 60: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 10: more on loops, max design pattern, random()

Indefinite (while) loops allow you torepeat a block of code as long as acondition holds.

Very useful for checking user inputfor correctness.

Python’s built-in random packagehas useful methods for generatingrandom whole numbers and realnumbers.

To use, must include:import random.

The max design pattern provides atemplate for finding maximum valuefrom a list.

CSci 127 (Hunter) Lecture 11 28 April 2020 21 / 47

Page 61: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 10: more on loops, max design pattern, random()

Indefinite (while) loops allow you torepeat a block of code as long as acondition holds.

Very useful for checking user inputfor correctness.

Python’s built-in random packagehas useful methods for generatingrandom whole numbers and realnumbers.

To use, must include:import random.

The max design pattern provides atemplate for finding maximum valuefrom a list.

CSci 127 (Hunter) Lecture 11 28 April 2020 21 / 47

Page 62: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 10: more on loops, max design pattern, random()

Indefinite (while) loops allow you torepeat a block of code as long as acondition holds.

Very useful for checking user inputfor correctness.

Python’s built-in random packagehas useful methods for generatingrandom whole numbers and realnumbers.

To use, must include:import random.

The max design pattern provides atemplate for finding maximum valuefrom a list.

CSci 127 (Hunter) Lecture 11 28 April 2020 21 / 47

Page 63: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Week 10: more on loops, max design pattern, random()

Indefinite (while) loops allow you torepeat a block of code as long as acondition holds.

Very useful for checking user inputfor correctness.

Python’s built-in random packagehas useful methods for generatingrandom whole numbers and realnumbers.

To use, must include:import random.

The max design pattern provides atemplate for finding maximum valuefrom a list.

CSci 127 (Hunter) Lecture 11 28 April 2020 21 / 47

Page 64: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Python & Circuits Review: 10 Weeks in 10 Minutes

Input/Output (I/O): input() and print();pandas for CSV files

Types:

I Primitive: int, float, bool, string;I Container: lists (but not dictionaries/hashes

or tuples)

Objects: turtles (used but did not design our own)

Loops: definite & indefinite

Conditionals: if-elif-else

Logical Expressions & Circuits

Functions: parameters & returns

Packages:

I Built-in: turtle, math, randomI Popular: numpy, matplotlib, pandas, folium

CSci 127 (Hunter) Lecture 11 28 April 2020 22 / 47

Page 65: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Today’s Topics

Design Patterns: Searching

Python Recap

Machine Language

Machine Language: Jumps & Loops

Binary & Hex Arithmetic

Final Exam: Format

CSci 127 (Hunter) Lecture 11 28 April 2020 23 / 47

Page 66: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Low-Level vs. High-Level Languages

(codeCommit)

Can view programming languages on a continuum.

Those that directly access machine instructions & memory and havelittle abstraction are low-level languages(e.g. machine language, assembly language).

Those that have strong abstraction (allow programming paradigmsindependent of the machine details, such as complex variables,functions and looping that do not translate directly into machinecode) are called high-level languages.

Some languages, like C, are in between– allowing both low levelaccess and high level data structures.

CSci 127 (Hunter) Lecture 11 28 April 2020 24 / 47

Page 67: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Low-Level vs. High-Level Languages

(codeCommit)

Can view programming languages on a continuum.

Those that directly access machine instructions & memory and havelittle abstraction are low-level languages

(e.g. machine language, assembly language).

Those that have strong abstraction (allow programming paradigmsindependent of the machine details, such as complex variables,functions and looping that do not translate directly into machinecode) are called high-level languages.

Some languages, like C, are in between– allowing both low levelaccess and high level data structures.

CSci 127 (Hunter) Lecture 11 28 April 2020 24 / 47

Page 68: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Low-Level vs. High-Level Languages

(codeCommit)

Can view programming languages on a continuum.

Those that directly access machine instructions & memory and havelittle abstraction are low-level languages(e.g. machine language, assembly language).

Those that have strong abstraction (allow programming paradigmsindependent of the machine details, such as complex variables,functions and looping that do not translate directly into machinecode) are called high-level languages.

Some languages, like C, are in between– allowing both low levelaccess and high level data structures.

CSci 127 (Hunter) Lecture 11 28 April 2020 24 / 47

Page 69: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Low-Level vs. High-Level Languages

(codeCommit)

Can view programming languages on a continuum.

Those that directly access machine instructions & memory and havelittle abstraction are low-level languages(e.g. machine language, assembly language).

Those that have strong abstraction (allow programming paradigmsindependent of the machine details, such as complex variables,functions and looping that do not translate directly into machinecode) are called high-level languages.

Some languages, like C, are in between– allowing both low levelaccess and high level data structures.

CSci 127 (Hunter) Lecture 11 28 April 2020 24 / 47

Page 70: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Low-Level vs. High-Level Languages

(codeCommit)

Can view programming languages on a continuum.

Those that directly access machine instructions & memory and havelittle abstraction are low-level languages(e.g. machine language, assembly language).

Those that have strong abstraction (allow programming paradigmsindependent of the machine details, such as complex variables,functions and looping that do not translate directly into machinecode) are called high-level languages.

Some languages, like C, are in between– allowing both low levelaccess and high level data structures.CSci 127 (Hunter) Lecture 11 28 April 2020 24 / 47

Page 71: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Machine Language

(Ruth Gordon & Ester Gerston programming the ENIAC, UPenn)

CSci 127 (Hunter) Lecture 11 28 April 2020 25 / 47

Page 72: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Machine Language

(wiki)

CSci 127 (Hunter) Lecture 11 28 April 2020 26 / 47

Page 73: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Machine Language

(wiki)

We will be writing programs in asimplified machine language, WeMIPS.

It is based on a reduced instruction setcomputer (RISC) design, originallydeveloped by the MIPS ComputerSystems.

Due to its small set of commands,processors can be designed to run thosecommands very efficiently.

More in future architecture classes....

CSci 127 (Hunter) Lecture 11 28 April 2020 27 / 47

Page 74: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Machine Language

(wiki)

We will be writing programs in asimplified machine language, WeMIPS.

It is based on a reduced instruction setcomputer (RISC) design, originallydeveloped by the MIPS ComputerSystems.

Due to its small set of commands,processors can be designed to run thosecommands very efficiently.

More in future architecture classes....

CSci 127 (Hunter) Lecture 11 28 April 2020 27 / 47

Page 75: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Machine Language

(wiki)

We will be writing programs in asimplified machine language, WeMIPS.

It is based on a reduced instruction setcomputer (RISC) design, originallydeveloped by the MIPS ComputerSystems.

Due to its small set of commands,processors can be designed to run thosecommands very efficiently.

More in future architecture classes....

CSci 127 (Hunter) Lecture 11 28 April 2020 27 / 47

Page 76: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Machine Language

(wiki)

We will be writing programs in asimplified machine language, WeMIPS.

It is based on a reduced instruction setcomputer (RISC) design, originallydeveloped by the MIPS ComputerSystems.

Due to its small set of commands,processors can be designed to run thosecommands very efficiently.

More in future architecture classes....

CSci 127 (Hunter) Lecture 11 28 April 2020 27 / 47

Page 77: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

“Hello World!” in Simplified Machine Language

(WeMIPS)

CSci 127 (Hunter) Lecture 11 28 April 2020 28 / 47

Page 78: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

WeMIPS

(Demo with WeMIPS)

CSci 127 (Hunter) Lecture 11 28 April 2020 29 / 47

Page 79: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

MIPS Commands

Registers: locations for storing information that can be quicklyaccessed.

Names start with ‘$’: $s0, $s1, $t0, $t1,...

R Instructions: Commands that use data in the registers:add $s1, $s2, $s3 (Basic form: OP rd, rs, rt)

I Instructions: instructions that also use intermediate values.addi $s1, $s2, 100 (Basic form: OP rd, rs, imm)

J Instructions: instructions that jump to another memory location.j done (Basic form: OP label)

CSci 127 (Hunter) Lecture 11 28 April 2020 30 / 47

Page 80: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

MIPS Commands

Registers: locations for storing information that can be quicklyaccessed. Names start with ‘$’: $s0, $s1, $t0, $t1,...

R Instructions: Commands that use data in the registers:add $s1, $s2, $s3 (Basic form: OP rd, rs, rt)

I Instructions: instructions that also use intermediate values.addi $s1, $s2, 100 (Basic form: OP rd, rs, imm)

J Instructions: instructions that jump to another memory location.j done (Basic form: OP label)

CSci 127 (Hunter) Lecture 11 28 April 2020 30 / 47

Page 81: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

MIPS Commands

Registers: locations for storing information that can be quicklyaccessed. Names start with ‘$’: $s0, $s1, $t0, $t1,...

R Instructions: Commands that use data in the registers:

add $s1, $s2, $s3 (Basic form: OP rd, rs, rt)

I Instructions: instructions that also use intermediate values.addi $s1, $s2, 100 (Basic form: OP rd, rs, imm)

J Instructions: instructions that jump to another memory location.j done (Basic form: OP label)

CSci 127 (Hunter) Lecture 11 28 April 2020 30 / 47

Page 82: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

MIPS Commands

Registers: locations for storing information that can be quicklyaccessed. Names start with ‘$’: $s0, $s1, $t0, $t1,...

R Instructions: Commands that use data in the registers:add $s1, $s2, $s3

(Basic form: OP rd, rs, rt)

I Instructions: instructions that also use intermediate values.addi $s1, $s2, 100 (Basic form: OP rd, rs, imm)

J Instructions: instructions that jump to another memory location.j done (Basic form: OP label)

CSci 127 (Hunter) Lecture 11 28 April 2020 30 / 47

Page 83: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

MIPS Commands

Registers: locations for storing information that can be quicklyaccessed. Names start with ‘$’: $s0, $s1, $t0, $t1,...

R Instructions: Commands that use data in the registers:add $s1, $s2, $s3 (Basic form: OP rd, rs, rt)

I Instructions: instructions that also use intermediate values.

addi $s1, $s2, 100 (Basic form: OP rd, rs, imm)

J Instructions: instructions that jump to another memory location.j done (Basic form: OP label)

CSci 127 (Hunter) Lecture 11 28 April 2020 30 / 47

Page 84: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

MIPS Commands

Registers: locations for storing information that can be quicklyaccessed. Names start with ‘$’: $s0, $s1, $t0, $t1,...

R Instructions: Commands that use data in the registers:add $s1, $s2, $s3 (Basic form: OP rd, rs, rt)

I Instructions: instructions that also use intermediate values.addi $s1, $s2, 100

(Basic form: OP rd, rs, imm)

J Instructions: instructions that jump to another memory location.j done (Basic form: OP label)

CSci 127 (Hunter) Lecture 11 28 April 2020 30 / 47

Page 85: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

MIPS Commands

Registers: locations for storing information that can be quicklyaccessed. Names start with ‘$’: $s0, $s1, $t0, $t1,...

R Instructions: Commands that use data in the registers:add $s1, $s2, $s3 (Basic form: OP rd, rs, rt)

I Instructions: instructions that also use intermediate values.addi $s1, $s2, 100 (Basic form: OP rd, rs, imm)

J Instructions: instructions that jump to another memory location.

j done (Basic form: OP label)

CSci 127 (Hunter) Lecture 11 28 April 2020 30 / 47

Page 86: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

MIPS Commands

Registers: locations for storing information that can be quicklyaccessed. Names start with ‘$’: $s0, $s1, $t0, $t1,...

R Instructions: Commands that use data in the registers:add $s1, $s2, $s3 (Basic form: OP rd, rs, rt)

I Instructions: instructions that also use intermediate values.addi $s1, $s2, 100 (Basic form: OP rd, rs, imm)

J Instructions: instructions that jump to another memory location.j done

(Basic form: OP label)

CSci 127 (Hunter) Lecture 11 28 April 2020 30 / 47

Page 87: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

MIPS Commands

Registers: locations for storing information that can be quicklyaccessed. Names start with ‘$’: $s0, $s1, $t0, $t1,...

R Instructions: Commands that use data in the registers:add $s1, $s2, $s3 (Basic form: OP rd, rs, rt)

I Instructions: instructions that also use intermediate values.addi $s1, $s2, 100 (Basic form: OP rd, rs, imm)

J Instructions: instructions that jump to another memory location.j done (Basic form: OP label)

CSci 127 (Hunter) Lecture 11 28 April 2020 30 / 47

Page 88: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

In Pairs or Triples:

Write a program that prints out the alphabet: a b c d ... x y z

CSci 127 (Hunter) Lecture 11 28 April 2020 31 / 47

Page 89: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

WeMIPS

(Demo with WeMIPS)

CSci 127 (Hunter) Lecture 11 28 April 2020 32 / 47

Page 90: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Today’s Topics

Design Patterns: Searching

Python Recap

Machine Language

Machine Language: Jumps & Loops

Binary & Hex Arithmetic

Final Exam: Format

CSci 127 (Hunter) Lecture 11 28 April 2020 33 / 47

Page 91: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Loops & Jumps in Machine Language

Instead of built-in looping structures like for

and while, you create your own loops by“jumping” to the location in the program.

Can indicate locations by writing labels at thebeginning of a line.

Then give a command to jump to thatlocation.

Different kinds of jumps:I Unconditional: j Done will jump to the

address with label Done.I Branch if Equal: beq $s0 $s1 DoAgain

will jump to the address with label DoAgainif the registers $s0 and $s1 contain the samevalue.

I See reading for more variations.

CSci 127 (Hunter) Lecture 11 28 April 2020 34 / 47

Page 92: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Loops & Jumps in Machine Language

Instead of built-in looping structures like for

and while, you create your own loops by“jumping” to the location in the program.

Can indicate locations by writing labels at thebeginning of a line.

Then give a command to jump to thatlocation.

Different kinds of jumps:I Unconditional: j Done will jump to the

address with label Done.I Branch if Equal: beq $s0 $s1 DoAgain

will jump to the address with label DoAgainif the registers $s0 and $s1 contain the samevalue.

I See reading for more variations.

CSci 127 (Hunter) Lecture 11 28 April 2020 34 / 47

Page 93: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Loops & Jumps in Machine Language

Instead of built-in looping structures like for

and while, you create your own loops by“jumping” to the location in the program.

Can indicate locations by writing labels at thebeginning of a line.

Then give a command to jump to thatlocation.

Different kinds of jumps:I Unconditional: j Done will jump to the

address with label Done.I Branch if Equal: beq $s0 $s1 DoAgain

will jump to the address with label DoAgainif the registers $s0 and $s1 contain the samevalue.

I See reading for more variations.

CSci 127 (Hunter) Lecture 11 28 April 2020 34 / 47

Page 94: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Loops & Jumps in Machine Language

Instead of built-in looping structures like for

and while, you create your own loops by“jumping” to the location in the program.

Can indicate locations by writing labels at thebeginning of a line.

Then give a command to jump to thatlocation.

Different kinds of jumps:

I Unconditional: j Done will jump to theaddress with label Done.

I Branch if Equal: beq $s0 $s1 DoAgain

will jump to the address with label DoAgainif the registers $s0 and $s1 contain the samevalue.

I See reading for more variations.

CSci 127 (Hunter) Lecture 11 28 April 2020 34 / 47

Page 95: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Loops & Jumps in Machine Language

Instead of built-in looping structures like for

and while, you create your own loops by“jumping” to the location in the program.

Can indicate locations by writing labels at thebeginning of a line.

Then give a command to jump to thatlocation.

Different kinds of jumps:I Unconditional: j Done will jump to the

address with label Done.

I Branch if Equal: beq $s0 $s1 DoAgain

will jump to the address with label DoAgainif the registers $s0 and $s1 contain the samevalue.

I See reading for more variations.

CSci 127 (Hunter) Lecture 11 28 April 2020 34 / 47

Page 96: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Loops & Jumps in Machine Language

Instead of built-in looping structures like for

and while, you create your own loops by“jumping” to the location in the program.

Can indicate locations by writing labels at thebeginning of a line.

Then give a command to jump to thatlocation.

Different kinds of jumps:I Unconditional: j Done will jump to the

address with label Done.I Branch if Equal: beq $s0 $s1 DoAgain

will jump to the address with label DoAgainif the registers $s0 and $s1 contain the samevalue.

I See reading for more variations.

CSci 127 (Hunter) Lecture 11 28 April 2020 34 / 47

Page 97: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Loops & Jumps in Machine Language

Instead of built-in looping structures like for

and while, you create your own loops by“jumping” to the location in the program.

Can indicate locations by writing labels at thebeginning of a line.

Then give a command to jump to thatlocation.

Different kinds of jumps:I Unconditional: j Done will jump to the

address with label Done.I Branch if Equal: beq $s0 $s1 DoAgain

will jump to the address with label DoAgainif the registers $s0 and $s1 contain the samevalue.

I See reading for more variations.

CSci 127 (Hunter) Lecture 11 28 April 2020 34 / 47

Page 98: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Jump Demo

(Demo with WeMIPS)

CSci 127 (Hunter) Lecture 11 28 April 2020 35 / 47

Page 99: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Today’s Topics

Design Patterns: Searching

Python Recap

Machine Language

Machine Language: Jumps & Loops

Binary & Hex Arithmetic

Final Exam: Format

CSci 127 (Hunter) Lecture 11 28 April 2020 36 / 47

Page 100: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.

I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 101: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.

I Example: what is 2A as a decimal number?2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 102: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 103: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2.

2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 104: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 105: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 106: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 107: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 108: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9.

9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 109: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 110: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 111: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.

CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 112: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Hexadecimal to Decimal: Converting Between Bases

(from i-programmer.info)

From hexadecimal to decimal:I Convert first digit to decimal and multiple by 16.I Convert second digit to decimal and add to total.I Example: what is 2A as a decimal number?

2 in decimal is 2. 2*16 is 32.

A in decimal digits is 10.

32 + 10 is 42.

Answer is 42.I Example: what is 99 as a decimal number?

9 in decimal is 9. 9*16 is 144.

9 in decimal digits is 9

144 + 9 is 153.

Answer is 153.CSci 127 (Hunter) Lecture 11 28 April 2020 37 / 47

Page 113: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.

I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 114: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.

I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 115: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.

I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 116: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.

I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 117: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.

I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 118: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.

I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 119: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.

I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 120: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.

I Example: what is 130 in binary notation?130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 121: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 122: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2.

First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 123: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1:

1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 124: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2.

Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 125: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0:

10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 126: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .

2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 127: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2.

Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 128: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0:

100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 129: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .

2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 130: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2.

Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 131: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0:

1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 132: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .

2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 133: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2.

Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 134: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0:

10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 135: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .

2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 136: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2.

Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 137: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0:

100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 138: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .

2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 139: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0.

Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 140: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1:

1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 141: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .

Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 142: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 143: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

From decimal to binary:

I Divide by 128 (= 27). Quotient is the first digit.I Divide remainder by 64 (= 26). Quotient is the next digit.I Divide remainder by 32 (= 25). Quotient is the next digit.I Divide remainder by 16 (= 24). Quotient is the next digit.I Divide remainder by 8 (= 23). Quotient is the next digit.I Divide remainder by 4 (= 22). Quotient is the next digit.I Divide remainder by 2 (= 21). Quotient is the next digit.I The last remainder is the last digit.I Example: what is 130 in binary notation?

130/128 is 1 rem 2. First digit is 1: 1 . . .2/64 is 0 rem 2. Next digit is 0: 10 . . .2/32 is 0 rem 2. Next digit is 0: 100 . . .2/16 is 0 rem 2. Next digit is 0: 1000 . . .2/8 is 0 rem 2. Next digit is 0: 10000 . . .2/4 is 0 remainder 2. Next digit is 0: 100000 . . .2/2 is 1 rem 0. Next digit is 1: 1000001 . . .Adding the last remainder: 10000010

CSci 127 (Hunter) Lecture 11 28 April 2020 38 / 47

Page 144: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 145: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99.

First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 146: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0:

0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 147: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35.

Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 148: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1:

01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 149: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .

35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 150: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3.

Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 151: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1:

011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 152: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .

3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 153: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3.

Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 154: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0:

0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 155: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .

3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 156: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3.

Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 157: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0:

01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 158: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .

3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 159: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3.

Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 160: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0:

011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 161: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .

3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 162: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1.

Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 163: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1:

0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 164: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .

Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 165: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 166: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Decimal to Binary: Converting Between Bases

Example: what is 99 in binary notation?

99/128 is 0 rem 99. First digit is 0: 0 . . .99/64 is 1 rem 35. Next digit is 1: 01 . . .35/32 is 1 rem 3. Next digit is 1: 011 . . .3/16 is 0 rem 3. Next digit is 0: 0110 . . .3/8 is 0 rem 3. Next digit is 0: 01100 . . .3/4 is 0 remainder 3. Next digit is 0: 011000 . . .3/2 is 1 rem 1. Next digit is 1: 0110001 . . .Adding the last remainder: 01100011

Answer is 1100011.

CSci 127 (Hunter) Lecture 11 28 April 2020 39 / 47

Page 167: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.

I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 168: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.

I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 169: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.

I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 170: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.

I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 171: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.

I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 172: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.

I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 173: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.

I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 174: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.

I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 175: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.

I Example: What is 111101 in decimal?Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 176: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with:

10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 177: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum:

11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 178: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 1

1*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 179: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum:

51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 180: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 5

1*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 181: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum:

131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 182: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 13

1*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 183: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum:

291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 184: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 29

1*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 185: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum:

61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 186: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 187: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

From binary to decimal:

I Set sum = last digit.I Multiply next digit by 2 = 21. Add to sum.I Multiply next digit by 4 = 22. Add to sum.I Multiply next digit by 8 = 23. Add to sum.I Multiply next digit by 16 = 24. Add to sum.I Multiply next digit by 32 = 25. Add to sum.I Multiply next digit by 64 = 26. Add to sum.I Multiply next digit by 128 = 27. Add to sum.I Sum is the decimal number.I Example: What is 111101 in decimal?

Sum starts with: 10*2 = 0. Add 0 to sum: 11*4 = 4. Add 4 to sum: 51*8 = 8. Add 8 to sum: 131*16 = 16. Add 16 to sum: 291*32 = 32. Add 32 to sum: 61

CSci 127 (Hunter) Lecture 11 28 April 2020 40 / 47

Page 188: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with:

00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 189: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum:

01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 190: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 0

1*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 191: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum:

40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 192: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 4

0*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 193: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum:

40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 194: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 4

0*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 195: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum:

41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 196: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 4

1*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 197: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum:

360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 198: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 36

0*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 199: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum:

361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 200: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 36

1*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 201: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum:

164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 202: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 203: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Binary to Decimal: Converting Between Bases

Example: What is 10100100 in decimal?

Sum starts with: 00*2 = 0. Add 0 to sum: 01*4 = 4. Add 4 to sum: 40*8 = 0. Add 0 to sum: 40*16 = 0. Add 0 to sum: 41*32 = 32. Add 32 to sum: 360*64 = 0. Add 0 to sum: 361*128 = 0. Add 128 to sum: 164

The answer is 164.

CSci 127 (Hunter) Lecture 11 28 April 2020 41 / 47

Page 204: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Challenge: Incrementers

Simplest arithmetic: add one (“increment”) a variable.

Example: Increment a decimal number:

def addOne(n):

m = n+1

return(m)

Challenge: Write an algorithm for incrementing numbers expressed as words.Example: "forty one" → "forty two"

Hint: Convert to numbers, increment, and convert back to strings.

Challenge: Write an algorithm for incrementing binary numbers.

Example: "1001" → "1010"

CSci 127 (Hunter) Lecture 11 28 April 2020 42 / 47

Page 205: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Challenge: Incrementers

Simplest arithmetic: add one (“increment”) a variable.

Example: Increment a decimal number:

def addOne(n):

m = n+1

return(m)

Challenge: Write an algorithm for incrementing numbers expressed as words.Example: "forty one" → "forty two"

Hint: Convert to numbers, increment, and convert back to strings.

Challenge: Write an algorithm for incrementing binary numbers.

Example: "1001" → "1010"

CSci 127 (Hunter) Lecture 11 28 April 2020 42 / 47

Page 206: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Challenge: Incrementers

Simplest arithmetic: add one (“increment”) a variable.

Example: Increment a decimal number:

def addOne(n):

m = n+1

return(m)

Challenge: Write an algorithm for incrementing numbers expressed as words.Example: "forty one" → "forty two"

Hint: Convert to numbers, increment, and convert back to strings.

Challenge: Write an algorithm for incrementing binary numbers.

Example: "1001" → "1010"

CSci 127 (Hunter) Lecture 11 28 April 2020 42 / 47

Page 207: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Challenge: Incrementers

Simplest arithmetic: add one (“increment”) a variable.

Example: Increment a decimal number:

def addOne(n):

m = n+1

return(m)

Challenge: Write an algorithm for incrementing numbers expressed as words.

Example: "forty one" → "forty two"

Hint: Convert to numbers, increment, and convert back to strings.

Challenge: Write an algorithm for incrementing binary numbers.

Example: "1001" → "1010"

CSci 127 (Hunter) Lecture 11 28 April 2020 42 / 47

Page 208: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Challenge: Incrementers

Simplest arithmetic: add one (“increment”) a variable.

Example: Increment a decimal number:

def addOne(n):

m = n+1

return(m)

Challenge: Write an algorithm for incrementing numbers expressed as words.Example: "forty one" → "forty two"

Hint: Convert to numbers, increment, and convert back to strings.

Challenge: Write an algorithm for incrementing binary numbers.

Example: "1001" → "1010"

CSci 127 (Hunter) Lecture 11 28 April 2020 42 / 47

Page 209: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Challenge: Incrementers

Simplest arithmetic: add one (“increment”) a variable.

Example: Increment a decimal number:

def addOne(n):

m = n+1

return(m)

Challenge: Write an algorithm for incrementing numbers expressed as words.Example: "forty one" → "forty two"

Hint: Convert to numbers, increment, and convert back to strings.

Challenge: Write an algorithm for incrementing binary numbers.

Example: "1001" → "1010"

CSci 127 (Hunter) Lecture 11 28 April 2020 42 / 47

Page 210: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Challenge: Incrementers

Simplest arithmetic: add one (“increment”) a variable.

Example: Increment a decimal number:

def addOne(n):

m = n+1

return(m)

Challenge: Write an algorithm for incrementing numbers expressed as words.Example: "forty one" → "forty two"

Hint: Convert to numbers, increment, and convert back to strings.

Challenge: Write an algorithm for incrementing binary numbers.

Example: "1001" → "1010"

CSci 127 (Hunter) Lecture 11 28 April 2020 42 / 47

Page 211: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Design Challenge: Incrementers

Simplest arithmetic: add one (“increment”) a variable.

Example: Increment a decimal number:

def addOne(n):

m = n+1

return(m)

Challenge: Write an algorithm for incrementing numbers expressed as words.Example: "forty one" → "forty two"

Hint: Convert to numbers, increment, and convert back to strings.

Challenge: Write an algorithm for incrementing binary numbers.

Example: "1001" → "1010"

CSci 127 (Hunter) Lecture 11 28 April 2020 42 / 47

Page 212: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Recap

Searching through data is a common task– built-infunctions and standard design patterns for this.

Programming languages can be classified by thelevel of abstraction and direct access to data.

CSci 127 (Hunter) Lecture 11 28 April 2020 43 / 47

Page 213: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Recap

Searching through data is a common task– built-infunctions and standard design patterns for this.

Programming languages can be classified by thelevel of abstraction and direct access to data.

CSci 127 (Hunter) Lecture 11 28 April 2020 43 / 47

Page 214: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Recap

Searching through data is a common task– built-infunctions and standard design patterns for this.

Programming languages can be classified by thelevel of abstraction and direct access to data.

CSci 127 (Hunter) Lecture 11 28 April 2020 43 / 47

Page 215: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Today’s Topics

Design Patterns: Searching

Python Recap

Machine Language

Machine Language: Jumps & Loops

Binary & Hex Arithmetic

Final Exam: Format

CSci 127 (Hunter) Lecture 11 28 April 2020 44 / 47

Page 216: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Administration

The exam will be administered through Gradescope.

The exam will be available on Gradescope only on May 18,9am-10:30am

There will be a different Gradescope Course called CSci 127 FinalExam

Prior to the exam you will be added to the final exam course for yourexam version.

The only assignment in that course will be your final exam.

The morning of the exam: log into Gradescope, find the CSci 127Final Exam course and open the assignment.

CSci 127 (Hunter) Lecture 11 28 April 2020 45 / 47

Page 217: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Administration

The exam will be administered through Gradescope.

The exam will be available on Gradescope only on May 18,9am-10:30am

There will be a different Gradescope Course called CSci 127 FinalExam

Prior to the exam you will be added to the final exam course for yourexam version.

The only assignment in that course will be your final exam.

The morning of the exam: log into Gradescope, find the CSci 127Final Exam course and open the assignment.

CSci 127 (Hunter) Lecture 11 28 April 2020 45 / 47

Page 218: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Administration

The exam will be administered through Gradescope.

The exam will be available on Gradescope only on May 18,9am-10:30am

There will be a different Gradescope Course called CSci 127 FinalExam

Prior to the exam you will be added to the final exam course for yourexam version.

The only assignment in that course will be your final exam.

The morning of the exam: log into Gradescope, find the CSci 127Final Exam course and open the assignment.

CSci 127 (Hunter) Lecture 11 28 April 2020 45 / 47

Page 219: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Administration

The exam will be administered through Gradescope.

The exam will be available on Gradescope only on May 18,9am-10:30am

There will be a different Gradescope Course called CSci 127 FinalExam

Prior to the exam you will be added to the final exam course for yourexam version.

The only assignment in that course will be your final exam.

The morning of the exam: log into Gradescope, find the CSci 127Final Exam course and open the assignment.

CSci 127 (Hunter) Lecture 11 28 April 2020 45 / 47

Page 220: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Administration

The exam will be administered through Gradescope.

The exam will be available on Gradescope only on May 18,9am-10:30am

There will be a different Gradescope Course called CSci 127 FinalExam

Prior to the exam you will be added to the final exam course for yourexam version.

The only assignment in that course will be your final exam.

The morning of the exam: log into Gradescope, find the CSci 127Final Exam course and open the assignment.

CSci 127 (Hunter) Lecture 11 28 April 2020 45 / 47

Page 221: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Administration

The exam will be administered through Gradescope.

The exam will be available on Gradescope only on May 18,9am-10:30am

There will be a different Gradescope Course called CSci 127 FinalExam

Prior to the exam you will be added to the final exam course for yourexam version.

The only assignment in that course will be your final exam.

The morning of the exam: log into Gradescope, find the CSci 127Final Exam course and open the assignment.

CSci 127 (Hunter) Lecture 11 28 April 2020 45 / 47

Page 222: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Format

Although the exam is remote, we still suggest you prepare 1 piece of8.5” x 11” paper.

I With notes, examples, programs: what will help you on the exam.I Best if you design/write yours since excellent way to study.

The exam format:I 10 questions, each worth 10 points.I Questions correspond to the course topics, and are variations on the

programming assignments, lab exercises, and lecture design challenges.I Style of questions: what does the code do? short answer, write

functions, top down design, & write complete programs.

Past exams available on webpage (includes answer keys).

CSci 127 (Hunter) Lecture 11 28 April 2020 46 / 47

Page 223: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Format

Although the exam is remote, we still suggest you prepare 1 piece of8.5” x 11” paper.

I With notes, examples, programs: what will help you on the exam.

I Best if you design/write yours since excellent way to study.

The exam format:I 10 questions, each worth 10 points.I Questions correspond to the course topics, and are variations on the

programming assignments, lab exercises, and lecture design challenges.I Style of questions: what does the code do? short answer, write

functions, top down design, & write complete programs.

Past exams available on webpage (includes answer keys).

CSci 127 (Hunter) Lecture 11 28 April 2020 46 / 47

Page 224: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Format

Although the exam is remote, we still suggest you prepare 1 piece of8.5” x 11” paper.

I With notes, examples, programs: what will help you on the exam.I Best if you design/write yours since excellent way to study.

The exam format:I 10 questions, each worth 10 points.I Questions correspond to the course topics, and are variations on the

programming assignments, lab exercises, and lecture design challenges.I Style of questions: what does the code do? short answer, write

functions, top down design, & write complete programs.

Past exams available on webpage (includes answer keys).

CSci 127 (Hunter) Lecture 11 28 April 2020 46 / 47

Page 225: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Format

Although the exam is remote, we still suggest you prepare 1 piece of8.5” x 11” paper.

I With notes, examples, programs: what will help you on the exam.I Best if you design/write yours since excellent way to study.

The exam format:

I 10 questions, each worth 10 points.I Questions correspond to the course topics, and are variations on the

programming assignments, lab exercises, and lecture design challenges.I Style of questions: what does the code do? short answer, write

functions, top down design, & write complete programs.

Past exams available on webpage (includes answer keys).

CSci 127 (Hunter) Lecture 11 28 April 2020 46 / 47

Page 226: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Format

Although the exam is remote, we still suggest you prepare 1 piece of8.5” x 11” paper.

I With notes, examples, programs: what will help you on the exam.I Best if you design/write yours since excellent way to study.

The exam format:I 10 questions, each worth 10 points.

I Questions correspond to the course topics, and are variations on theprogramming assignments, lab exercises, and lecture design challenges.

I Style of questions: what does the code do? short answer, writefunctions, top down design, & write complete programs.

Past exams available on webpage (includes answer keys).

CSci 127 (Hunter) Lecture 11 28 April 2020 46 / 47

Page 227: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Format

Although the exam is remote, we still suggest you prepare 1 piece of8.5” x 11” paper.

I With notes, examples, programs: what will help you on the exam.I Best if you design/write yours since excellent way to study.

The exam format:I 10 questions, each worth 10 points.I Questions correspond to the course topics, and are variations on the

programming assignments, lab exercises, and lecture design challenges.

I Style of questions: what does the code do? short answer, writefunctions, top down design, & write complete programs.

Past exams available on webpage (includes answer keys).

CSci 127 (Hunter) Lecture 11 28 April 2020 46 / 47

Page 228: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Format

Although the exam is remote, we still suggest you prepare 1 piece of8.5” x 11” paper.

I With notes, examples, programs: what will help you on the exam.I Best if you design/write yours since excellent way to study.

The exam format:I 10 questions, each worth 10 points.I Questions correspond to the course topics, and are variations on the

programming assignments, lab exercises, and lecture design challenges.I Style of questions: what does the code do? short answer, write

functions, top down design, & write complete programs.

Past exams available on webpage (includes answer keys).

CSci 127 (Hunter) Lecture 11 28 April 2020 46 / 47

Page 229: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Final Overview: Format

Although the exam is remote, we still suggest you prepare 1 piece of8.5” x 11” paper.

I With notes, examples, programs: what will help you on the exam.I Best if you design/write yours since excellent way to study.

The exam format:I 10 questions, each worth 10 points.I Questions correspond to the course topics, and are variations on the

programming assignments, lab exercises, and lecture design challenges.I Style of questions: what does the code do? short answer, write

functions, top down design, & write complete programs.

Past exams available on webpage (includes answer keys).

CSci 127 (Hunter) Lecture 11 28 April 2020 46 / 47

Page 230: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Exam Options

Final Exam, Version 3

CSci 127: Introduction to Computer Science

Hunter College, City University of New York

19 December 2018

Exam Rules

• Show all your work. Your grade will be based on the work shown.

• The exam is closed book and closed notes with the exception of an 8 1/2” x 11” piece of paperfilled with notes, programs, etc.

• When taking the exam, you may have with you pens and pencils, and your note sheet.

• You may not use a computer, calculator, tablet, smart watch, or other electronic device.

• Do not open this exam until instructed to do so.

Hunter College regards acts of academic dishonesty (e.g., plagiarism, cheating on examinations,obtaining unfair advantage, and falsification of records and o�cial documents) as serious o↵ensesagainst the values of intellectual honesty. The College is committed to enforcing the CUNY Policyon Academic Integrity and will pursue cases of academic dishonesty according to the Hunter CollegeAcademic Integrity Procedures.

I understand that all cases of academic dishonesty will be reported to the Dean of Students andwill result in sanctions.

Name:

EmpID:

Email:

Signature:

Exam Times:

Default: Regular Time: Monday, 18 May,9-10:30am.

Alternate Time: Reading Day, Friday, 15May, 8:00am-9:30am.

Accessibility Testing: For double timemust contact Prof. Ligorio by 15 May.

Grading Options:

Default: Letter Grade.

Credit/NoCredit grade– availabilitydepends on major and academic standing.

Survey for your choices will be available next lecture.No survey answer implies you will take the exam on 18 May,

regular time and letter grade.

CSci 127 (Hunter) Lecture 11 28 April 2020 47 / 47

Page 231: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Exam Options

Final Exam, Version 3

CSci 127: Introduction to Computer Science

Hunter College, City University of New York

19 December 2018

Exam Rules

• Show all your work. Your grade will be based on the work shown.

• The exam is closed book and closed notes with the exception of an 8 1/2” x 11” piece of paperfilled with notes, programs, etc.

• When taking the exam, you may have with you pens and pencils, and your note sheet.

• You may not use a computer, calculator, tablet, smart watch, or other electronic device.

• Do not open this exam until instructed to do so.

Hunter College regards acts of academic dishonesty (e.g., plagiarism, cheating on examinations,obtaining unfair advantage, and falsification of records and o�cial documents) as serious o↵ensesagainst the values of intellectual honesty. The College is committed to enforcing the CUNY Policyon Academic Integrity and will pursue cases of academic dishonesty according to the Hunter CollegeAcademic Integrity Procedures.

I understand that all cases of academic dishonesty will be reported to the Dean of Students andwill result in sanctions.

Name:

EmpID:

Email:

Signature:

Exam Times:

Default: Regular Time: Monday, 18 May,9-10:30am.

Alternate Time: Reading Day, Friday, 15May, 8:00am-9:30am.

Accessibility Testing: For double timemust contact Prof. Ligorio by 15 May.

Grading Options:

Default: Letter Grade.

Credit/NoCredit grade– availabilitydepends on major and academic standing.

Survey for your choices will be available next lecture.No survey answer implies you will take the exam on 18 May,

regular time and letter grade.

CSci 127 (Hunter) Lecture 11 28 April 2020 47 / 47

Page 232: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Exam Options

Final Exam, Version 3

CSci 127: Introduction to Computer Science

Hunter College, City University of New York

19 December 2018

Exam Rules

• Show all your work. Your grade will be based on the work shown.

• The exam is closed book and closed notes with the exception of an 8 1/2” x 11” piece of paperfilled with notes, programs, etc.

• When taking the exam, you may have with you pens and pencils, and your note sheet.

• You may not use a computer, calculator, tablet, smart watch, or other electronic device.

• Do not open this exam until instructed to do so.

Hunter College regards acts of academic dishonesty (e.g., plagiarism, cheating on examinations,obtaining unfair advantage, and falsification of records and o�cial documents) as serious o↵ensesagainst the values of intellectual honesty. The College is committed to enforcing the CUNY Policyon Academic Integrity and will pursue cases of academic dishonesty according to the Hunter CollegeAcademic Integrity Procedures.

I understand that all cases of academic dishonesty will be reported to the Dean of Students andwill result in sanctions.

Name:

EmpID:

Email:

Signature:

Exam Times:

Default: Regular Time: Monday, 18 May,9-10:30am.

Alternate Time: Reading Day, Friday, 15May, 8:00am-9:30am.

Accessibility Testing: For double timemust contact Prof. Ligorio by 15 May.

Grading Options:

Default: Letter Grade.

Credit/NoCredit grade– availabilitydepends on major and academic standing.

Survey for your choices will be available next lecture.No survey answer implies you will take the exam on 18 May,

regular time and letter grade.

CSci 127 (Hunter) Lecture 11 28 April 2020 47 / 47

Page 233: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Exam Options

Final Exam, Version 3

CSci 127: Introduction to Computer Science

Hunter College, City University of New York

19 December 2018

Exam Rules

• Show all your work. Your grade will be based on the work shown.

• The exam is closed book and closed notes with the exception of an 8 1/2” x 11” piece of paperfilled with notes, programs, etc.

• When taking the exam, you may have with you pens and pencils, and your note sheet.

• You may not use a computer, calculator, tablet, smart watch, or other electronic device.

• Do not open this exam until instructed to do so.

Hunter College regards acts of academic dishonesty (e.g., plagiarism, cheating on examinations,obtaining unfair advantage, and falsification of records and o�cial documents) as serious o↵ensesagainst the values of intellectual honesty. The College is committed to enforcing the CUNY Policyon Academic Integrity and will pursue cases of academic dishonesty according to the Hunter CollegeAcademic Integrity Procedures.

I understand that all cases of academic dishonesty will be reported to the Dean of Students andwill result in sanctions.

Name:

EmpID:

Email:

Signature:

Exam Times:

Default: Regular Time: Monday, 18 May,9-10:30am.

Alternate Time: Reading Day, Friday, 15May, 8:00am-9:30am.

Accessibility Testing: For double timemust contact Prof. Ligorio by 15 May.

Grading Options:

Default: Letter Grade.

Credit/NoCredit grade– availabilitydepends on major and academic standing.

Survey for your choices will be available next lecture.No survey answer implies you will take the exam on 18 May,

regular time and letter grade.

CSci 127 (Hunter) Lecture 11 28 April 2020 47 / 47

Page 234: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Exam Options

Final Exam, Version 3

CSci 127: Introduction to Computer Science

Hunter College, City University of New York

19 December 2018

Exam Rules

• Show all your work. Your grade will be based on the work shown.

• The exam is closed book and closed notes with the exception of an 8 1/2” x 11” piece of paperfilled with notes, programs, etc.

• When taking the exam, you may have with you pens and pencils, and your note sheet.

• You may not use a computer, calculator, tablet, smart watch, or other electronic device.

• Do not open this exam until instructed to do so.

Hunter College regards acts of academic dishonesty (e.g., plagiarism, cheating on examinations,obtaining unfair advantage, and falsification of records and o�cial documents) as serious o↵ensesagainst the values of intellectual honesty. The College is committed to enforcing the CUNY Policyon Academic Integrity and will pursue cases of academic dishonesty according to the Hunter CollegeAcademic Integrity Procedures.

I understand that all cases of academic dishonesty will be reported to the Dean of Students andwill result in sanctions.

Name:

EmpID:

Email:

Signature:

Exam Times:

Default: Regular Time: Monday, 18 May,9-10:30am.

Alternate Time: Reading Day, Friday, 15May, 8:00am-9:30am.

Accessibility Testing: For double timemust contact Prof. Ligorio by 15 May.

Grading Options:

Default: Letter Grade.

Credit/NoCredit grade– availabilitydepends on major and academic standing.

Survey for your choices will be available next lecture.

No survey answer implies you will take the exam on 18 May,regular time and letter grade.

CSci 127 (Hunter) Lecture 11 28 April 2020 47 / 47

Page 235: CSci 127: Introduction to Computer Science...I list: a sequence of items e.g. [3, 1, 4, 5, 9] or [’violet’,’purple’,’indigo’] I class variables: for complex objects, like

Exam Options

Final Exam, Version 3

CSci 127: Introduction to Computer Science

Hunter College, City University of New York

19 December 2018

Exam Rules

• Show all your work. Your grade will be based on the work shown.

• The exam is closed book and closed notes with the exception of an 8 1/2” x 11” piece of paperfilled with notes, programs, etc.

• When taking the exam, you may have with you pens and pencils, and your note sheet.

• You may not use a computer, calculator, tablet, smart watch, or other electronic device.

• Do not open this exam until instructed to do so.

Hunter College regards acts of academic dishonesty (e.g., plagiarism, cheating on examinations,obtaining unfair advantage, and falsification of records and o�cial documents) as serious o↵ensesagainst the values of intellectual honesty. The College is committed to enforcing the CUNY Policyon Academic Integrity and will pursue cases of academic dishonesty according to the Hunter CollegeAcademic Integrity Procedures.

I understand that all cases of academic dishonesty will be reported to the Dean of Students andwill result in sanctions.

Name:

EmpID:

Email:

Signature:

Exam Times:

Default: Regular Time: Monday, 18 May,9-10:30am.

Alternate Time: Reading Day, Friday, 15May, 8:00am-9:30am.

Accessibility Testing: For double timemust contact Prof. Ligorio by 15 May.

Grading Options:

Default: Letter Grade.

Credit/NoCredit grade– availabilitydepends on major and academic standing.

Survey for your choices will be available next lecture.No survey answer implies you will take the exam on 18 May,

regular time and letter grade.

CSci 127 (Hunter) Lecture 11 28 April 2020 47 / 47