csci 127: introduction to computer science · 2020-01-16 · sheet, no devices such as computers,...

241
CSci 127: Introduction to Computer Science hunter.cuny.edu/csci CSci 127 (Hunter) Lecture 11 21 November 2018 1 / 46

Upload: others

Post on 01-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

CSci 127: Introduction to Computer Science

hunter.cuny.edu/csci

CSci 127 (Hunter) Lecture 11 21 November 2018 1 / 46

Page 2: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Announcements

No classes Thursday or Friday due to theThanksgiving holiday.

Lab will close early today (7pm) due to theholiday.

Have a great Thanksgiving!

CSci 127 (Hunter) Lecture 11 21 November 2018 2 / 46

Page 3: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Announcements

No classes Thursday or Friday due to theThanksgiving holiday.

Lab will close early today (7pm) due to theholiday.

Have a great Thanksgiving!

CSci 127 (Hunter) Lecture 11 21 November 2018 2 / 46

Page 4: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Announcements

No classes Thursday or Friday due to theThanksgiving holiday.

Lab will close early today (7pm) due to theholiday.

Have a great Thanksgiving!

CSci 127 (Hunter) Lecture 11 21 November 2018 2 / 46

Page 5: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!

No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 6: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 7: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?

The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 8: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.

We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 9: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 10: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?

The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 11: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 12: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 13: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.

I We’ll have a mock exam during the last lecture (12 December).F Same format as real final: seating alphabetically, sign-in/sign-out, note

sheet, no devices such as computers, calculators, phones, or watches.F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 14: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 15: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 16: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.

F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 17: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 18: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?

Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 19: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Frequently Asked Questions

From lecture slips & recitation sections.

Help! Binary & hexadecimal numbers make no sense!No worries– we’ll start off with those in today’s lecture.

Why can’t in-class quizzes taken at midnight count towards my grade?The in-class quizzes are in place of midterm exams.We want to know that you (and not friend/family) took the in-class quiz.

When is the final? Is there a review sheet?The final is Wednesday, 19 December, 9-11am.

Instead of a review sheet, we have:

I All previous final exams (and answer keys) on the website.I We’ll have a mock exam during the last lecture (12 December).

F Same format as real final: seating alphabetically, sign-in/sign-out, notesheet, no devices such as computers, calculators, phones, or watches.

F We will use the sign-out sheets to give credit for the lecture slip.F Answer key will be available after lecture.

Can we do more on design patterns?Yes, but we’re going to transition to C++ after Thanksgiving.

CSci 127 (Hunter) Lecture 11 21 November 2018 3 / 46

Page 20: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Today’s Topics

Data Representation

Machine Language: Jumps & Loops

Recap of Python & Circuits

Design Patterns: Sorting

CSci 127 (Hunter) Lecture 11 21 November 2018 4 / 46

Page 21: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:

I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 22: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.

I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 23: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.

I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 24: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.

I Example: what is 200 in hexadecimal notation?200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 25: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 26: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 27: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C.

8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 28: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 29: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.

I Example: what is 31 in hexadecimal notation?31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 30: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 31: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 32: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1.

15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 33: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 34: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Converting between bases

(from i-programmer.info)

From decimal to hexadecimal:I Divide by 16.I Convert quotient and remainder into hex digits.I Write down in that order to give hex notation.I Example: what is 200 in hexadecimal notation?

200/16 is 12 remainder 8.

12 in hex digits is C. 8 in hex digits is 8.

Answer is C8.I Example: what is 31 in hexadecimal notation?

31/16 is 1 remainder 15.

1 in hex digits is 1. 15 in hex digits is F.

Answer is 1F.

CSci 127 (Hunter) Lecture 11 21 November 2018 5 / 46

Page 35: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 36: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 37: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 38: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 39: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 40: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 41: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 42: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 43: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 44: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 45: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 46: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 47: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 6 / 46

Page 48: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 49: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 50: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 51: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 52: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 53: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 54: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 55: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 56: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 57: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 58: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 59: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 60: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 61: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 62: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 63: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 64: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 65: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 66: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 67: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 68: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 69: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 70: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 71: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 72: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 73: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 74: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 75: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 76: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 77: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 78: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 7 / 46

Page 79: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 80: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 81: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 82: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 83: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 84: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 85: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 86: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 87: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 88: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 89: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 90: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 91: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 92: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 93: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 94: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 95: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 96: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 97: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 98: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 99: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 100: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 101: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 8 / 46

Page 102: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 103: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 104: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 105: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 106: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 107: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 108: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 109: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 110: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 111: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 112: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 113: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 114: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 115: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 116: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 117: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 118: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 119: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 120: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 121: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 122: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 9 / 46

Page 123: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 124: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 125: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 126: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 127: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 128: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 129: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 130: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 131: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 132: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 133: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 134: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 135: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 136: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 137: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 138: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 10 / 46

Page 139: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Today’s Topics

Data Representation

Machine Language: Jumps & Loops

Recap of Python & Circuits

Design Patterns: Sorting

CSci 127 (Hunter) Lecture 11 21 November 2018 11 / 46

Page 140: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 12 / 46

Page 141: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 12 / 46

Page 142: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 12 / 46

Page 143: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 12 / 46

Page 144: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 13 / 46

Page 145: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 13 / 46

Page 146: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 13 / 46

Page 147: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 13 / 46

Page 148: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 13 / 46

Page 149: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 13 / 46

Page 150: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 13 / 46

Page 151: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 13 / 46

Page 152: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: 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 21 November 2018 13 / 46

Page 153: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 14 / 46

Page 154: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 14 / 46

Page 155: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 14 / 46

Page 156: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 14 / 46

Page 157: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 14 / 46

Page 158: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 14 / 46

Page 159: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 14 / 46

Page 160: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

WeMIPS

(Demo with WeMIPS)

CSci 127 (Hunter) Lecture 11 21 November 2018 15 / 46

Page 161: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Today’s Topics

Data Representation

Machine Language: Jumps & Loops

Recap of Python & Circuits

Design Patterns: Sorting

CSci 127 (Hunter) Lecture 11 21 November 2018 16 / 46

Page 162: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Python & Circuits Review: 10 Weeks in 10 Minutes

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

CSci 127 (Hunter) Lecture 11 21 November 2018 17 / 46

Page 163: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 18 / 46

Page 164: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 18 / 46

Page 165: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 18 / 46

Page 166: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 19 / 46

Page 167: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 19 / 46

Page 168: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 19 / 46

Page 169: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 19 / 46

Page 170: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 19 / 46

Page 171: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 19 / 46

Page 172: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 19 / 46

Page 173: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 19 / 46

Page 174: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 19 / 46

Page 175: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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

CSci 127 (Hunter) Lecture 11 21 November 2018 20 / 46

Page 176: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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

CSci 127 (Hunter) Lecture 11 21 November 2018 20 / 46

Page 177: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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

CSci 127 (Hunter) Lecture 11 21 November 2018 20 / 46

Page 178: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 21 / 46

Page 179: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 21 / 46

Page 180: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 21 / 46

Page 181: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 21 / 46

Page 182: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Week 4: design problem (cropping images) & decisions

CSci 127 (Hunter) Lecture 11 21 November 2018 22 / 46

Page 183: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 23 / 46

Page 184: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 23 / 46

Page 185: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 24 / 46

Page 186: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 24 / 46

Page 187: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 24 / 46

Page 188: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 24 / 46

Page 189: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 24 / 46

Page 190: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 25 / 46

Page 191: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 25 / 46

Page 192: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 25 / 46

Page 193: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 25 / 46

Page 194: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 25 / 46

Page 195: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 25 / 46

Page 196: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 25 / 46

Page 197: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 26 / 46

Page 198: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 26 / 46

Page 199: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 26 / 46

Page 200: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 26 / 46

Page 201: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 26 / 46

Page 202: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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 21 November 2018 27 / 46

Page 203: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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

CSci 127 (Hunter) Lecture 11 21 November 2018 28 / 46

Page 204: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Week 10: more on loops, searching data, random(),machine language

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.

CSci 127 (Hunter) Lecture 11 21 November 2018 29 / 46

Page 205: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Week 10: more on loops, searching data, random(),machine language

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.

CSci 127 (Hunter) Lecture 11 21 November 2018 29 / 46

Page 206: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Week 10: more on loops, searching data, random(),machine language

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.

CSci 127 (Hunter) Lecture 11 21 November 2018 29 / 46

Page 207: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Week 10: more on loops, searching data, random(),machine language

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.

CSci 127 (Hunter) Lecture 11 21 November 2018 29 / 46

Page 208: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

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

Simplified Machine Language

CSci 127 (Hunter) Lecture 11 21 November 2018 30 / 46

Page 209: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Today’s Topics

Data Representation

Machine Language: Jumps & Loops

Recap of Python & Circuits

Design Patterns: Sorting

CSci 127 (Hunter) Lecture 11 21 November 2018 31 / 46

Page 210: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Sorting Demo

1 Let num be the number of items in the list.

2 Repeat num times:

I If the first in line is taller than thesecond, switch places.

I Next check if the current second inline is taller than the third.

I If so, switch places.I Repeat until you reach the end of

the list.

CSci 127 (Hunter) Lecture 11 21 November 2018 32 / 46

Page 211: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Sorting Demo

1 Let num be the number of items in the list.

2 Repeat num times:

I If the first in line is taller than thesecond, switch places.

I Next check if the current second inline is taller than the third.

I If so, switch places.I Repeat until you reach the end of

the list.

CSci 127 (Hunter) Lecture 11 21 November 2018 32 / 46

Page 212: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Sorting Demo

1 Let num be the number of items in the list.

2 Repeat num times:

I If the first in line is taller than thesecond, switch places.

I Next check if the current second inline is taller than the third.

I If so, switch places.I Repeat until you reach the end of

the list.

CSci 127 (Hunter) Lecture 11 21 November 2018 32 / 46

Page 213: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Sorting Demo

1 Let num be the number of items in the list.

2 Repeat num times:

I If the first in line is taller than thesecond, switch places.

I Next check if the current second inline is taller than the third.

I If so, switch places.I Repeat until you reach the end of

the list.

CSci 127 (Hunter) Lecture 11 21 November 2018 32 / 46

Page 214: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Sorting Demo

1 Let num be the number of items in the list.

2 Repeat num times:

I If the first in line is taller than thesecond, switch places.

I Next check if the current second inline is taller than the third.

I If so, switch places.

I Repeat until you reach the end ofthe list.

CSci 127 (Hunter) Lecture 11 21 November 2018 32 / 46

Page 215: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Sorting Demo

1 Let num be the number of items in the list.

2 Repeat num times:

I If the first in line is taller than thesecond, switch places.

I Next check if the current second inline is taller than the third.

I If so, switch places.I Repeat until you reach the end of

the list.

CSci 127 (Hunter) Lecture 11 21 November 2018 32 / 46

Page 216: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Sorting Demo

Show sorting demo.

CSci 127 (Hunter) Lecture 11 21 November 2018 33 / 46

Page 217: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Lecture Slip: Design Patterns

In pairs or triples:

Fill in the UTAs’ name at the top ofthe sheet.

What does the code do?

CSci 127 (Hunter) Lecture 11 21 November 2018 34 / 46

Page 218: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Python, Languages, & Design

On lecture slip, write down a topic you wish wehad spent more time (and why).

Python language

Logical Circuits

Simplified Machine Language

Design: from written description (‘specs’) tofunction inputs & outputs (‘APIs’)

Pass your lecture slips to the aisles for the UTAsto collect.

CSci 127 (Hunter) Lecture 11 21 November 2018 35 / 46

Page 219: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Python, Languages, & Design

On lecture slip, write down a topic you wish wehad spent more time (and why).

Python language

Logical Circuits

Simplified Machine Language

Design: from written description (‘specs’) tofunction inputs & outputs (‘APIs’)

Pass your lecture slips to the aisles for the UTAsto collect.

CSci 127 (Hunter) Lecture 11 21 November 2018 35 / 46

Page 220: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Python, Languages, & Design

On lecture slip, write down a topic you wish wehad spent more time (and why).

Python language

Logical Circuits

Simplified Machine Language

Design: from written description (‘specs’) tofunction inputs & outputs (‘APIs’)

Pass your lecture slips to the aisles for the UTAsto collect.

CSci 127 (Hunter) Lecture 11 21 November 2018 35 / 46

Page 221: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Python, Languages, & Design

On lecture slip, write down a topic you wish wehad spent more time (and why).

Python language

Logical Circuits

Simplified Machine Language

Design: from written description (‘specs’) tofunction inputs & outputs (‘APIs’)

Pass your lecture slips to the aisles for the UTAsto collect.

CSci 127 (Hunter) Lecture 11 21 November 2018 35 / 46

Page 222: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Python, Languages, & Design

On lecture slip, write down a topic you wish wehad spent more time (and why).

Python language

Logical Circuits

Simplified Machine Language

Design: from written description (‘specs’) tofunction inputs & outputs (‘APIs’)

Pass your lecture slips to the aisles for the UTAsto collect.

CSci 127 (Hunter) Lecture 11 21 November 2018 35 / 46

Page 223: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Recap: Python, Languages, & Design

On lecture slip, write down a topic you wish wehad spent more time (and why).

Python language

Logical Circuits

Simplified Machine Language

Design: from written description (‘specs’) tofunction inputs & outputs (‘APIs’)

Pass your lecture slips to the aisles for the UTAsto collect.

CSci 127 (Hunter) Lecture 11 21 November 2018 35 / 46

Page 224: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final Overview: Top-Down Design & APIsFor each question, write only the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that takes a weight in kilograms and returns theweight in pounds.

Write a function that takes a string and returns its length.

Write a function that, given a DataFrame, returns the minimal valuein the first column.

Write a function that takes a whole number and returns thecorresponding binary number as a string.

Write a function that computes the total monthly payment whengiven the initial loan amount, annual interest rate, number of years ofthe loan.

(Hint: highlight key words, make list of inputs, list of outputs, then puttogether.)

CSci 127 (Hunter) Lecture 11 21 November 2018 36 / 46

Page 225: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final Overview: Top-Down Design & APIsFor each question, write only the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that takes a weight in kilograms and returns theweight in pounds.

Write a function that takes a string and returns its length.

Write a function that, given a DataFrame, returns the minimal valuein the first column.

Write a function that takes a whole number and returns thecorresponding binary number as a string.

Write a function that computes the total monthly payment whengiven the initial loan amount, annual interest rate, number of years ofthe loan.

(Hint: highlight key words, make list of inputs, list of outputs, then puttogether.)

CSci 127 (Hunter) Lecture 11 21 November 2018 36 / 46

Page 226: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final Overview: Top-Down Design & APIsFor each question, write only the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that takes a weight in kilograms and returns theweight in pounds.

Write a function that takes a string and returns its length.

Write a function that, given a DataFrame, returns the minimal valuein the first column.

Write a function that takes a whole number and returns thecorresponding binary number as a string.

Write a function that computes the total monthly payment whengiven the initial loan amount, annual interest rate, number of years ofthe loan.

(Hint: highlight key words, make list of inputs, list of outputs, then puttogether.)

CSci 127 (Hunter) Lecture 11 21 November 2018 36 / 46

Page 227: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that takes a weight in kilograms and returns theweight in pounds.

def kg2lbs(kg):

...

return(lbs)

CSci 127 (Hunter) Lecture 11 21 November 2018 37 / 46

Page 228: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that takes a weight in kilograms and returns theweight in pounds.

def kg2lbs(kg):

...

return(lbs)

CSci 127 (Hunter) Lecture 11 21 November 2018 37 / 46

Page 229: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that takes a weight in kilograms and returns theweight in pounds.

def kg2lbs(kg)

lbs = kg * 2.2

return(lbs)

CSci 127 (Hunter) Lecture 11 21 November 2018 38 / 46

Page 230: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that takes a string and returns its length.

def sLength(str):

...

return(length)

CSci 127 (Hunter) Lecture 11 21 November 2018 39 / 46

Page 231: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that takes a string and returns its length.

def sLength(str):

...

return(length)

CSci 127 (Hunter) Lecture 11 21 November 2018 39 / 46

Page 232: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that takes a string and returns its length.

def sLength(str):

length = len(str)

return(length)

CSci 127 (Hunter) Lecture 11 21 November 2018 40 / 46

Page 233: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that, given a DataFrame, returns the minimal valuein the “Manhattan” column.

def getMin(df):

...

return(min)

CSci 127 (Hunter) Lecture 11 21 November 2018 41 / 46

Page 234: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that, given a DataFrame, returns the minimal valuein the “Manhattan” column.

def getMin(df):

...

return(min)

CSci 127 (Hunter) Lecture 11 21 November 2018 41 / 46

Page 235: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that, given a DataFrame, returns the minimal valuein the “Manhattan” column.

def getMin(df):

min = df[’Manhattan’].min()

return(min)

CSci 127 (Hunter) Lecture 11 21 November 2018 42 / 46

Page 236: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that takes a whole number and returns thecorresponding binary number as a string.

def num2bin(num):

...

return(bin)

CSci 127 (Hunter) Lecture 11 21 November 2018 43 / 46

Page 237: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that takes a whole number and returns thecorresponding binary number as a string.

def num2bin(num):

...

return(bin)

CSci 127 (Hunter) Lecture 11 21 November 2018 43 / 46

Page 238: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that takes a whole number and returns thecorresponding binary number as a string.

def num2bin(num):

binStr = ""

while (num > 0):

#Divide by 2, and add the remainder to the string

r = num %2

binString = str(r) + binStr

num = num / 2

return(binStr)

CSci 127 (Hunter) Lecture 11 21 November 2018 44 / 46

Page 239: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that computes the total monthly payment whengiven the initial loan amount, annual interest rate, number of years ofthe loan.

def computePayment(loan,rate,year):

....

return(payment)

CSci 127 (Hunter) Lecture 11 21 November 2018 45 / 46

Page 240: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question, write the function header (name & inputs) and returnvalues (often called the Application Programming Interface (API)):

Write a function that computes the total monthly payment whengiven the initial loan amount, annual interest rate, number of years ofthe loan.

def computePayment(loan,rate,year):

....

return(payment)

CSci 127 (Hunter) Lecture 11 21 November 2018 45 / 46

Page 241: CSci 127: Introduction to Computer Science · 2020-01-16 · sheet, no devices such as computers, calculators, phones, or watches. F We will use the sign-out sheets to give credit

Final OverviewFor each question below, write the function header (name & inputs) andreturn values (often called the Application Programming Interface (API)):

Write a function that computes the total monthly payment whengiven the initial loan amount, annual interest rate, number of years ofthe loan.

def computePayment(loan,rate,year):

(Some formula for payment)

return(payment)

CSci 127 (Hunter) Lecture 11 21 November 2018 46 / 46