{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture08

# lecture08 - Lecture 8 Dictionaries Caltech CS 1 Fall 2010 A...

This preview shows pages 1–15. Sign up to view the full content.

Caltech CS 1: Fall 2010 Lecture 8 : October 20, 2010 Dictionaries

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Caltech CS 1: Fall 2010 A bunch of mostly-unrelated topics: Booleans and boolean operators Using for loops with files The range function Tuples The enumerate function Sequence slices
Caltech CS 1: Fall 2010 Binary numbers and hexadecimal numbers Dictionaries (a new data type) Dictionaries and for loops Dictionary methods

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Caltech CS 1: Fall 2010
Caltech CS 1: Fall 2010 We normally compute using decimal numbers numbers composed of ten digits: 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , and 9 This is only one of many ways to represent numbers Other ways include: Roman numerals: MMIX (2009) Sequence of 1s: 1111111111 (10)

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Caltech CS 1: Fall 2010 Computers normally use binary numbers only two digits: 0 and 1 Reason: it's easy to build digital electronic circuits using binary numbers 0 is "low voltage" 1 is "high voltage" Any number that can be represented as a decimal number can also be represented as a binary number so computers use binary numbers for convenience
Caltech CS 1: Fall 2010 Decimal numbers are also called base 10 numbers Binary numbers are base 2 numbers Also often use base 16 numbers (hexadecimal) Here, we'll show how to convert from binary numbers to decimal numbers We'll restrict ourselves to integers >= 0 for simplicity

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Caltech CS 1: Fall 2010 A binary number consists only of 0 s and 1 s, e.g. : 11010 What is this number in decimal notation?
Caltech CS 1: Fall 2010 Recall: what does a decimal number mean? The number 1234 means: 1 x 10 3 + 2 x 10 2 + 3 x 10 1 + 4 x 10 0 = 1 x 1000 + 2 x 100 + 3 x 10 + 4 x 1 = 1234 1000 , 100 , 10 , and 1 are all powers of 10 So we say that 1234 is written in base 10 Or 1234 10 if we want to be very explicit

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Caltech CS 1: Fall 2010 Binary numbers use powers of 2, not 10 The number 11010 means: 1 x 2 4 + 1 x 2 3 + 0 x 2 2 + 1 x 2 1 + 0 x 2 0 = 1 x 16 + 1 x 8 + 0 x 4 + 1 x 2 + 0 x 1 = 26 16 , 8 , 4 , 2 , and 1 are all powers of 2 So we say that 11010 is written in base 2 Or 11010 2 if we want to be very explicit
Caltech CS 1: Fall 2010 Note: the same number (like 11010 ) can mean something very different in binary and decimal number systems! 11010 (binary) = twenty six 11010 (decimal) = eleven thousand and ten Usually obvious from context which number system we mean If not, use a subscript: 11010 10 for decimal 11010 2 for binary

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Caltech CS 1: Fall 2010 We've seen how to convert binary numbers to their decimal equivalents Converting decimal to binary is significantly more complicated makes a great lab problem won't cover here
Caltech CS 1: Fall 2010 A number's value does not depend on the way it's represented The same number can have many different representations Use the one that's most convenient Since computers "talk" in binary, we need to be able to understand it too but most of the time, it doesn't matter

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Caltech CS 1: Fall 2010 Computer does all of its arithmetic in binary We usually input data as decimal So computer must convert decimal binary do computations in binary convert back to decimal for human viewing
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern