124
Encoding Things for Computers Section 17.1 Chapter 3

Encoding Things for Computers Section 17.1 Chapter 3

Embed Size (px)

Citation preview

  • Slide 1
  • Slide 2
  • Encoding Things for Computers Section 17.1 Chapter 3
  • Slide 3
  • Watson http://www.youtube.com/watch?v=WFR3lOm_xhE
  • Slide 4
  • Digital vs Analog Digital is to analog as steps are to ramps.
  • Slide 5
  • Digital vs Analog.
  • Slide 6
  • .
  • Slide 7
  • Standards A very old idea. Sometimes there arent any. But theyre very common. And theres a general trend in the direction of standards.
  • Slide 8
  • A Very Old Idea Along the Danube River
  • Slide 9
  • No Standards
  • Slide 10
  • Not Much of a Standard
  • Slide 11
  • Some Common Standards
  • Slide 12
  • A Small Number of Standards
  • Slide 13
  • Slide 14
  • Slide 15
  • Bitten by Lack of a Single Standard
  • Slide 16
  • Slide 17
  • Slide 18
  • Wishing for Standards http://www.sheldonbrown.com/tire-sizing.html
  • Slide 19
  • A General Trend Toward Standards Word Sizes of Early Computers EDVAC44 bits1947 MARK 140 bits1948 EDSAC17 bits1949 CSIRAC20 bits1949 UNIVAC I12 digits1951 IBM 70136 bits1952 CDC 160448 bits1959 CDC 660060 bits1964 IBM 36032 bits1965 x-8616 bits1978 x-3232 bits1986 x-6464 bits2004
  • Slide 20
  • Integers 1040 1 1 0 1 0 0 0 The first step is obvious:
  • Slide 21
  • What About Long Integers? n! : if n = 1 then 1 else n * (n-1)! def factorial(n): result = 1 for j in range(1,n+1): result = result * j return (result)
  • Slide 22
  • Integers 1040 1 1 0 1 0 0 0 The first step was obvious: But what about this: -104 1 1 1 0 1 0 0 0 sign bit
  • Slide 23
  • Two Problems sign bit -1041 1 1 0 1 0 0 0 Two representations of 0: Adder and subtractor have to check sign bit and branch accordingly. The best representation: Should make things easy for the computer. Since people dont matter: well never see it.
  • Slide 24
  • Twos Complement 104 0 1 1 0 1 0 0 0 -104: 1 0 0 1 0 1 1 1 Flip the bits: Add 1: 1 0 0 1 1 0 0 0 A good explanation of why it works: http://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html
  • Slide 25
  • But What Happens Now? 11011001 + 11100101
  • Slide 26
  • But What Happens Now? 11011001 + 11100101 Overflow, if we stick with a fixed-length word (which Python doesnt do)
  • Slide 27
  • Another Problem 104.23 What should we do about:
  • Slide 28
  • Another Problem 104.23 What should we do about: If we always want two places after. : Then we could write: 10423 And then always treat it as though the decimal point were there.
  • Slide 29
  • Floating Point Well do it in decimal: NumberFloating Point 4.324.32e0
  • Slide 30
  • Floating Point Well do it in decimal: NumberFloating Point 4.324.32e0 456.24.56e+2 Multiply by 10 2
  • Slide 31
  • Floating Point Well do it in decimal: NumberFloating Point 4.324.32e0 456.24.56e+2.00044.0e-4 Multiply by 10 -4
  • Slide 32
  • Floating Point Well do it in decimal: NumberFloating Point 4.324.32e0 456.24.56e+2.00044.0e-4 56784657846352*345262511960561349752268586352 Note: Python will create very large integers.
  • Slide 33
  • Floating Point Well do it in decimal: NumberFloating Point 4.324.32e0 456.24.56e+2.00044.0e-4 56784657846352*345262511960561349752268586352 1960561349752268586352/29.802806748761343e+20
  • Slide 34
  • Rounding Error >>> 156738*.028 4388.664 >>> int(_) 4388 >>> Where did the.664 cents go? We can force Python to round instead of truncate. Our balance is $1,567.38 and the interest rate is 2.8%:
  • Slide 35
  • Rounding Error But what about this: Our balance is $1,567.38 and the interest rate is 2.8%: >>> 156738*.028 4388.664 >>> int(_ +.5) 4389 >>> >>> 166730*.05 8336.5 >>>
  • Slide 36
  • Salami Slicing
  • Slide 37
  • Text Computers have revolutionized our world. They have changed the course of our daily lives, the way we do science, the way we entertain ourselves, the way that business is conducted, and the way we protect our security.
  • Slide 38
  • Text Computers have revolutionized our world. They have changed the course of our daily lives, the way we do science, the way we entertain ourselves, the way that business is conducted, and the way we protect our security. Les ordinateurs ont rvolutionn notre monde. Ils ont chang le cours de notre vie quotidienne, notre faon de faire la science, la faon dont nous nous divertissons, la faon dont les affaires sont menes, et la faon dont nous protgeons notre scurit.
  • Slide 39
  • Text Computers have revolutionized our world. They have changed the course of our daily lives, the way we do science, the way we entertain ourselves, the way that business is conducted, and the way we protect our security. Les ordinateurs ont rvolutionn notre monde. Ils ont chang le cours de notre vie quotidienne, notre faon de faire la science, la faon dont nous nous divertissons, la faon dont les affaires sont menes, et la faon dont nous protgeons notre scurit.
  • Slide 40
  • Representing Text Decide how many characters we need to represent. Determine the required number of bits. ASCII: 7 bits. Can encode 2 7 = 128 different symbols. At the time (1963), it was felt that this was enough. Much concern about data transmission speed. The 8 th bit, if available, could be used for a parity bit.
  • Slide 41
  • ASCII http://www.krisl.net/cgi-bin/ascbin.pl
  • Slide 42
  • Representing Text Fourscore and seven F o u r 01000110 01101111 01110101 01110010
  • Slide 43
  • Representing Text T h e n u m b e r i s 1 7. 54 68 65 20 6E 75 6D 62 65 72 20 69 73 20 31 37 2E
  • Slide 44
  • Computing with Text Computers have revolutionized our world. They have changed the course of our daily lives, the way we do science, the way we entertain ourselves, the way that business is conducted, and the way we protect our security. Suppose we want to capitalize this entire paragraph: Lets go back and look at the ASCII table to see how to do that.
  • Slide 45
  • Computing with Text in Python chr(65) ord('A') ord('A') + 32 st = chr(_) mystuff = 'Now is the time ') mystuff.upper()
  • Slide 46
  • When We Need More Characters What about things like:
  • Slide 47
  • When We Need More Characters What about things like: Answer: Unicode A conversion applet: http://www.pinyin.info/tools/converter/chars2uninumbers.html
  • Slide 48
  • Unicode Unicode lists 1,114,112 code points in the range: 0 16 to 10FFFF 16 divided into seventeen planes: the basic multilingual plane, and 16 supplementary planes), each with 65,536 (= 2 16 ) code points. http://www.unicode.org/charts/
  • Slide 49
  • Unicode There exist different ways of mapping those 1,114,112 code points to specific byte patterns. In December, 2007 UTF-8 surpassed Ascii on the Web. Watch them stream by: http://www.babelstone.co.uk/Unicode/unicode.html
  • Slide 50
  • Saving Space Key idea: Common things should be short. Natural languages evolve to do this. Examples: http://www.paulnoll.com/Books/Clear-English/English-3000-common-words.html
  • Slide 51
  • Saving Space Key idea: Common things should be short. Samuel Morse:
  • Slide 52
  • Saving Space Key idea: Common things should be short. Huffman coding:
  • Slide 53
  • Saving Space Key idea: Common things should be short. UTF-8 encoding of Unicode http://en.wikipedia.org/wiki/UTF-8
  • Slide 54
  • But What Do Symbols Look Like? Computers have revolutionized our world.
  • Slide 55
  • The Basic Idea results = google(text, query)
  • Slide 56
  • The Basic Idea results = google(text, query) if word_count(text) > 5000: return(Done!!) else: return(No sleep yet.)
  • Slide 57
  • The Basic Idea results = google(text, query) if word_count(text) > 5000: return(Done!!) else: return(No sleep yet. display = render(text, font)
  • Slide 58
  • Pixel Based Fonts
  • Slide 59
  • Slide 60
  • TrueType Fonts Each symbol is represented as a set of lines and Bzier curves: Then code associated with each display device turns the description into pixels or rasters as necessary. So a font is just another file of bits.
  • Slide 61
  • The First Part of the Arial TrueType Font File ???????pDSIG$=???|GDEF^#]r?u???GSUB?u?? JSTFm*i?l???LTSHe C?t???6VDMXPj??#??cmap @j:????jcvt *v?? ??0fpgmyY??0??ngasp???t???glyf??bhdmx ??4??(head&??|???6hhea3?????$hmtx4X@??P??(kern7a96?`??`locaai2????,maxp G????? namee;??? post~?2??AprepR?? ?? ??????_ N?C?&???????????????????????v? ???/?V?? ??????3??3???f ??z??????????Mono?@? Q3 >@???????????9??9??9??^s?s?I ?wV?X?Z?|?|?@?r9??A9?9??s?Us?s?