lecture08

lecture08 - Lecture 8: October 20, 2010 Dictionaries...

Info iconThis preview shows pages 1–14. Sign up to view the full content.

View Full Document Right Arrow Icon
Caltech CS 1: Fall 2010 Lecture 8 : October 20, 2010 Dictionaries
Background image of page 1

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

View Full DocumentRight Arrow Icon
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
Background image of page 2
Caltech CS 1: Fall 2010 Binary numbers and hexadecimal numbers Dictionaries (a new data type) Dictionaries and for loops Dictionary methods
Background image of page 3

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

View Full DocumentRight Arrow Icon
Caltech CS 1: Fall 2010
Background image of page 4
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)
Background image of page 5

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

View Full DocumentRight Arrow Icon
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
Background image of page 6
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
Background image of page 7

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

View Full DocumentRight Arrow Icon
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?
Background image of page 8
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
Background image of page 9

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

View Full DocumentRight Arrow Icon
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
Background image of page 10
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
Background image of page 11

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

View Full DocumentRight Arrow Icon
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
Background image of page 12
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
Background image of page 13

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

View Full DocumentRight Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 67

lecture08 - Lecture 8: October 20, 2010 Dictionaries...

This preview shows document pages 1 - 14. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online