Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases.

Similar presentations


Presentation on theme: "CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases."— Presentation transcript:

1 CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases

2 Announcements Copies of the slides are available on Blackboard and the course web page before and after each class The end is near! All drop/add slips must be turned in by Sept. 7 th. I have a cool office. Please stop by and look (you could also me questions you have at the same time).

3 Converting binary to decimal Binary positional notation d n * 2 n-1 + d n-1 * 2 n-2 + … + d 2 * 2 1 + d 1 * 2 0 What is binary 1101 in decimal? d 4 = 1d 3 = 1d 2 = 0d 1 = 1 1101 = 1 * 2 3 + 1 * 2 2 + 0 * 2 1 + 1 * 2 0 = 8 + 4 + 0 + 1 = 13

4 Converting octal to decimal Octal positional notation d n * 8 n-1 + d n-1 * 8 n-2 + … + d 2 * 8 1 + d 1 * 8 0 What is octal 126 in decimal d 3 = 1d 2 = 2d 1 = 6 126 = 1 * 8 2 + 2 * 8 1 + 6 * 8 0 = 64 + 16 + 6 = 86

5 Self-Quiz What is the decimal number equal to:  Binary 1110?  Binary 100101?  Octal 31?  Octal 17?

6 Base 16 Also known as hexadecimal Uses 10 expected digits:  0, 1, 2, 3, 4, 5, 6, 7, 8, 9 Still needs 6 more; by convention we use:  A, B, C, D, E, F  A == “10”, B == “11”, C == “12”, …, F == “15”

7 Converting Hex to Decimal Equation converting base 16 to base 10: What is the decimal value of hex FACE?

8 Powers-of-Two Conversion Converting between binary and octal or hex is easy  Why? How many bits per octal digit? How many bits per nibble (hex digit)?

9 Converting Binary to Hex What is 1111111011101101 in hex? What is 1111101011001110 in hex?

10 Converting Hex to Binary What is 65D3 in binary? What is BEEF is binary?

11 Converting Octal and Binary What is octal 6743 in binary? What is binary 101110100010001 in octal?

12 Converting from Base 10 Early programmers wrote programs entirely in binary  Decimal notation still rare today. Why?

13 Converting from Base 10 Conversion follows simple algorithm: Do Divide decimal number by new base Next left-most digit is remainder from division Replace decimal number with division quotient Repeat until decimal number is zero

14 Convert Decimal to Binary What is 10 (decimal) in binary?

15 Self-Test Convert into from decimal to binary:  14  63

16 Convert Decimal to Hex Convert 48813 from decimal to hex

17 Converting to/from decimal? Who is ready for this on midterm?  What questions do you have? If you are uncomfortable asking in class:  Ask anyway (others have same questions)!  Ask me in my office hours  Post anonymously on blackboard  Try exercises 28 – 34 in book (p. 48-49)

18 Addition Refresher How do we add two numbers together?

19 Adding in other bases Rules are very synonmous  Carry the one when above value of base  For instance in base 2: 1 + 1 10  Or in base 8: 4 + 4 10

20 Adding binary numbers 101010 + 110001 111110 + 11

21 Adding hexadecimal numbers FEED +FACE BEEF + EA7

22 Subtraction Refresher Subtraction is base 10: 7213 - 6999

23 Subtraction in other bases Rules are very synonmous  Borrow the value of base when necessary  For instance in base 2: 2 10 - 1 1  Or in base 8: 16 - 7 7

24 Subtracting octal numbers 7535 - 3536 4562 - 777

25 Subtracting binary numbers 10110110 - 1010001 10000000 - 1111111

26 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?

27 Encoding Data 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

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

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

30 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

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

32 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)

33 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

34 2 types 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 Lossy compression  No(table) because data is lost in compression  Useful when not all data is important E.g. mp3 files remove sounds people cannot hear

35 Compression Ratios Another way to compare algorithms is their compression rate  Measures how well data are compressed  Expressed as a value between 0% and 100% 0%  perfect compression 100%  no compression Most algorithms lie somewhere in between

36 For Next Lecture Have Chapter 3 finished Be ready to discuss:  Hexadecimal numbers  Converting from decimal to other bases  Arithmetic in bases other than 10


Download ppt "CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases."

Similar presentations


Ads by Google