Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 110 – Intro to Computing Lecture 4: Arithmetic in other bases & Encoding Data.

Similar presentations


Presentation on theme: "CSC 110 – Intro to Computing Lecture 4: Arithmetic in other bases & Encoding Data."— Presentation transcript:

1 CSC 110 – Intro to Computing Lecture 4: Arithmetic in other bases & Encoding Data

2 Announcements Copies of the slides are available on Blackboard and the course web page before and after each class I have a cool office. Please stop by and look (you could also me questions you have at the same time).

3 Addition Refresher How do we add two numbers together?

4 Adding in other bases Rules are very synonmous  Carry the one when above value of base For the digit being computed, record the sum minus the base  For instance in base 2: 1 + 1 10  Or in base 8: 4 + 5 11

5 Adding hexadecimal numbers FEED +FACE BEEF + EA7

6 Data Encoding Data (“information”) is traditionally encoded in analog formats  Falls along a continuum with lots of minimal changes Color changes when mixing paint Rising mercury levels when temperature increases  Easy for nature, but hard to capture numerically How to capture precision: Is it 71.848174 o F or 71.848173 o F?

7 Data Encoding Easier to encode discrete data  E.g., Using integer or rational numbers 71 o F or 4.5 miles.  Also bounds space needed to record data For this reason, computers only use discrete data

8 Digitizing Data Computers work in binary (0-1)  Makes computing cheaper and simpler  Limited loss of precision: Can convert all integers into binary How come this conversion is possible?

9 CD Encoding 1 stored as bump 0 stored as pit

10 CD Encoding Laser light shines onto spinning disc  Bumps reflect laser well  Pits scatter laser light  Receptor records amount of light received  Based upon level, determines if is a “0” or “1”  CD player converts string of bits into sounds

11 Digitizing Data Figure 3.3 Signals in this region considered 0 Signals in this region considered 1 How digital data is captured and processed

12 Binary Representation 1 bit captures 2 states: 0 or 1 2 bits captures 4 states: 00, 01, 10, 11 3 bits capture 8 states: 000, 001, 010, 011, 100, 101, 110, 111

13 Binary Representation How many states can 4 bits capture? How many different states can n bits represent?

14 Data Storage Storing data can require lots of space  Each pixel (dot) in a color photo takes 4 bytes  5 megapixel (~million pixel) camera: 20MB per picture  32 pictures: 640MB (a CD holds 650MB)

15 Compression Much of this data is repetitive or unneeded  Areas in pictures contain similar data Pixels of clothing, leaves, or the sky will be similar  Music contains lots of sounds we cannot hear Compression limits the space data uses

16 Compression Ratios Compare algorithms by compression rate  Measures how well data are compressed  Expressed as a value between 0% and ???% 0%  perfect compression (not really possible) 100%  no compression 110%  compressed data is 10 % larger Most algorithms lie somewhere in between Algorithms rate depends on input data

17 First type of compression Lossless compression  Lmt spce tkn w/o losing data  Important when all data is important E.g., bank records, grade reports, census data

18 Keyword Encoding Useful method of compressing text Idea: Words occur commonly in English  Encode: Replace words with single symbols  Decode: Replace symbols with words  What words would be good to replace?  How should these be chosen?

19 Keyword Encoding We will compress common words with single characters  as  ^  the  ~  and  +  that  $  must  &

20 Keyword Encoding Example Raw Text: To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings & arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; No more; & by a sleep to say we end

21 Keyword Encoding Example Encoded Text: To be, or not to be: $ is ~ question: Whe~r 'tis nobler in ~ mind to suffer The slings & arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end ~m? To die: to sleep; No more; & by a sleep to say we end

22 Keyword Encoding Example Decoded Text: To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings must arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; No more; must by a sleep to say we end

23 Keyword Encoding Example Oops! We accidentally expanded symbols that were in the original text  Also, were unable to compress word “The” because it was capitalized How could we get around these problems?

24 Run-Length Encoding Takes advantage of repeated characters  Not useful for English  Very useful for DNA Replaces text with first character, flag, and one digit number of repeated characters  Consider if we make ‘*’ the flag character

25 Run-Length Encoding BAAAAAAAB  BA*7B BAAAAAAAAAAB  BA*9AB  Can only handle single digit replacement  How can we fix this?

26 Run-Length Encoding Variable number of digit replacement:  BAAAAAAAAAAB  BA*10B  BAAAAAAAAAA1B  BA*101B Oops… Why not increase digits for replacement?

27 Run-Length Encoding How would we encode this text Raw Text: A*7AAAA Encoded Text: A*7A*3 Decoded Text: AAAAAAAAAA How can we solve this problem?

28 Huffman Coding Invented by Dr. David Huffman Based upon idea that not all characters are equal  Why use as much space on ‘s’ as ‘q’?  Encode characters with space inversely proportional to frequency used

29 Problems With Huffman Coding Very difficult to figure out algorithm  Need to make sure that initial bits match only one character  Luckily, Dr. Huffman solved this problem How do we decide frequency of usage? What problems would bad encoding cause?

30 Second compression type Lossy compression  No(table) because data is lost in compression  Useful when not all data is important

31 Sound Encoding Many modern ways of encoding sound  mp3 (created by Fraunhofer, defined in MPEG-3 Audio layer 3 standard)  aac (created by Apple, included in MPEG-4 standard)  wma (created by Microsoft, not made available to any standards body)

32 Sound Encoding All of these format use “psycho-acoustic model”  Analyze how the human brain hears sound  Filter out sounds brain cannot process  Compress remaining notes mp3 uses Huffman encoding

33 Psycho-acoustic models Hard to encode music  Need to process sounds through models Easy to decode music  All filtering already done  Only need to reverse Huffman encoding Is this a good trade-off?

34 For Next Lecture Have Chapter 4 started Be ready to discuss:  Boolean logic  AND, OR, XOR, NOT, NAND, NOR gates


Download ppt "CSC 110 – Intro to Computing Lecture 4: Arithmetic in other bases & Encoding Data."

Similar presentations


Ads by Google