CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases.
-
date post
21-Dec-2015 -
Category
Documents
-
view
220 -
download
1
Transcript of CSC 110 – Intro to Computing Lecture 3: Converting between bases & Arithmetic in other bases.
CSC 110 –Intro to Computing
Lecture 3:
Converting between bases & Arithmetic in other bases
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. 7th.
I have a cool office. Please stop by and look (you could also me questions you have at the same time).
Converting binary to decimal
Binary positional notationdn * 2n-1 + dn-1 * 2n-2 + … + d2 * 21 + d1 * 20
What is binary 1101 in decimal?d4 = 1 d3 = 1 d2 = 0 d1 = 1
1101 = 1 * 23 + 1 * 22 + 0 * 21 + 1 * 20
= 8 + 4 + 0 + 1 = 13
Converting octal to decimal
Octal positional notationdn * 8n-1 + dn-1 * 8n-2 + … + d2 * 81 + d1 * 80
What is octal 126 in decimald3 = 1 d2 = 2 d1 = 6
126 = 1 * 82 + 2 * 81 + 6 * 80
= 64 + 16 + 6= 86
Self-Quiz
What is the decimal number equal to:Binary 1110?
Binary 100101?
Octal 31?
Octal 17?
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, FA == “10”, B == “11”, C == “12”, …, F == “15”
Converting Hex to Decimal
Equation converting base 16 to base 10:
What is the decimal value of hex FACE?
Powers-of-Two Conversion
Converting between binary and octal or hex is easyWhy?
How many bits per octal digit?
How many bits per nibble (hex digit)?
Converting Binary to Hex
What is 1111111011101101 in hex?
What is 1111101011001110 in hex?
Converting Hex to Binary
What is 65D3 in binary?
What is BEEF is binary?
Converting Octal and Binary
What is octal 6743 in binary?
What is binary 101110100010001 in octal?
Converting from Base 10
Early programmers wrote programs entirely in binaryDecimal notation still rare today. Why?
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
Convert Decimal to Binary
What is 10 (decimal) in binary?
Self-Test
Convert into from decimal to binary:14
63
Convert Decimal to Hex
Convert 48813 from decimal to hex
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 hoursPost anonymously on blackboardTry exercises 28 – 34 in book (p. 48-49)
Addition Refresher
How do we add two numbers together?
71262331
589311
Adding in other bases
Rules are very synonmousCarry the one when above value of baseFor instance in base 2: 1
+ 1 10
Or in base 8: 4+ 4 10
Adding binary numbers
101010 + 110001
111110+ 11
Adding hexadecimal numbers
FEED+FACE
BEEF+ EA7
Subtraction Refresher
Subtraction is base 10:
7213- 6999
Subtraction in other bases
Rules are very synonmousBorrow the value of base when necessaryFor instance in base 2: 2
10- 1 1
Or in base 8: 16
- 7 7
Subtracting octal numbers
7535- 3536
4562- 777
Subtracting binary numbers
10110110- 1010001
10000000- 1111111
Data Encoding
Data (“information”) is traditionally encoded in analog formatsFalls 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.848174oF or
71.848173oF?
Encoding Data
Easier to encode discrete dataE.g., Using integer or rational numbers
71oF or 4.5 miles.Also bounds space needed to record data
For this reason, computers only use discrete data
Digitizing Data
Computers work in binary (0-1)Makes computing cheaper and simplerLimited loss of precision:
Can convert all integers into binary
How does this work?
Digitizing Data
Figure 3.3
Signals in this region considered 0
Signals in this region considered 1
How digital data is captured and processed
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
Binary Representation
How many states can 4 bits capture?
How many different states can n bits represent?
Data Storage
Storing data can require lots of spaceEach pixel (dot) in a color photo takes 4 bytes5 megapixel (~million pixel) camera:
20MB per picture32 pictures: 640MB (a CD holds 650MB)
Compression
Much of this data is repetitive or unneededAreas 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
2 types of compression
Lossless compressionLmt spce tkn w/o losing data Important when all data is important
E.g., bank records, grade reports, census data
Lossy compressionNo(table) because data is lost in compressionUseful when not all data is important
E.g. mp3 files remove sounds people cannot hear
Compression Ratios
Another way to compare algorithms is their compression rateMeasures how well data are compressedExpressed as a value between 0% and 100%
0% perfect compression 100% no compression Most algorithms lie somewhere in between
For Next Lecture
Have Chapter 3 finished Be ready to discuss:
Hexadecimal numbersConverting from decimal to other basesArithmetic in bases other than 10