Each column represents another power of the base

Slides:



Advertisements
Similar presentations
Information Representation
Advertisements

Data Representation COE 202 Digital Logic Design Dr. Aiman El-Maleh
The Binary Numbering Systems
Hexadecimal In today’s lesson we will look at: the need for something other than binary how hexadecimal works how to convert between hexadecimal and binary.
Bit Depth and Spatial Resolution SIMG-201 Survey of Imaging Science © 2002 CIS/RIT.
Connecting with Computer Science, 2e
CSC 110 – Intro to Computing Lecture 4: Arithmetic in other bases & Encoding Data.
Professor Jennifer Rexford COS 217
Binary Conversion In today’s lesson we will link together the binary and algorithm topics by looking at how to get the computer to: convert binary to decimal.
Data storage Charles McAnany. What are the ones and zeroes? Hard drive Computer "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod.
Binary Numbers.
Binary Conversions Number systems Binary to decimal Decimal to binary.
Connecting with Computer Science 2 Objectives Learn why numbering systems are important to understand Refresh your knowledge of powers of numbers Learn.
Real Numbers and the Decimal Number System
Bit Patterns – Day 2 Scott Baranick & Daniel Velasquez.
What's ahead? Conway gives a whole new outlook on "loopy" ! John Conway 10/18 no class - Fall break 10/19 no new hw due 10/11 Dynamic & binary data 10/12.
Computers Organization & Assembly Language
Numeration Systems Introduction to Binary, Octal, and Hexadecimal.
Lab #5-6 Follow-Up: More Python; Images Images ● A signal (e.g. sound, temperature infrared sensor reading) is a single (one- dimensional) quantity that.
Data Representation S2. This unit covers how the computer represents- Numbers Text Graphics Control.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 14 Introduction to Computer Graphics.
Foundations of Computer Science Computing …it is all about Data Representation, Storage, Processing, and Communication of Data 10/4/20151CS 112 – Foundations.
Lec 3: Data Representation Computer Organization & Assembly Language Programming.
© 1999 Rochester Institute of Technology Introduction to Digital Imaging.
Computer Math. The Decimal System How do we represent “One Hundred and Twenty Five”? How do we represent “One Hundred and Twenty Five”? Simple: 125 !!!
Compsci Today’s topics l Binary Numbers  Brookshear l Slides from Prof. Marti Hearst of UC Berkeley SIMS l Upcoming  Networks Interactive.
Binary Arithmetic In today’s lesson we will look at: a reminder of how binary works adding binary numbers overflow complements negative numbers and subtraction.
Number Systems CIT Network Math
Compsci Today’s topics l Binary Numbers  Brookshear l Slides from Prof. Marti Hearst of UC Berkeley SIMS l Upcoming  Networks Interactive.
1 COMS 161 Introduction to Computing Title: The Digital Domain Date: September 6, 2004 Lecture Number: 6.
Announcement!!! First exam next Thursday (I’m trying to give you a first exam before the drop date) I’ll post a sample exam over the weekend and will try.
Finding Red Pixels – Part 2 Prof. Noah Snavely CS1114
POWERPOINT PLUS 11/17/07 Class Notes. WHAT IS A PIXEL A pixel is a number that represents the intensity of light at a square spot in the picture. Pixels.
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
COMPUTER PROGRAMMING I Objective 1.02 Understand Numbering Systems.
Computer Science LESSON 2 ON Number Bases.
More Digital Representation Discrete information is represented in binary (PandA), and “continuous” information is made discrete.
Information in Computers. Remember Computers Execute algorithms Need to be told what to do And to whom to do it.
Unit 1 Digital Data Section D. Chapter 1, Slide 2Starting Out with Visual Basic 3 rd EditionIntroduction to ComputersUnit 1D – Digital DataSlide 2 Wikipedia.
Week 3 - Monday.  What did we talk about last time?  Video games  Lab 2.
AP CSP: Pixelation – B&W/Color Images
Chapter 8 & 11: Representing Information Digitally
Week 2 - Wednesday CS 121.
Image Processing Objectives To understand pixel based image processing
Data Representation.
Lec 3: Data Representation
Week 3 - Monday CS 113.
Discrete Mathematics Numbering System.
Computer Science Higher
CMSC201 Computer Science I for Majors Lecture 22 – Binary (and More)
Introduction to Computers
Reading Netpbm Images.
Last Class We Covered File I/O How to open a file
Tools of Web Development 1: Module A: Numbering Systems
Number Bases In today’s lesson we will look at:
CS320n –Visual Programming
To do … Web Exercise: Quiz-3, HW#2 Score: update
Number Bases In today’s lesson we will look at:
Data Representation.
Representing Images 2.6 – Data Representation.
Ch2: Data Representation
Numbers and their bases
Topic 3: Data Hexadecimal.
COMS 161 Introduction to Computing
Objective 1.02 Understand Numbering Systems
Starter Using the fingers on only one hand, what is the highest number you can count to? Rules: You must start at 1 You must count sequentially (i.e.
Last Class We Covered File I/O How to open a file
Basic Concepts of Digital Imaging
Do it now activity Use the coloured pencils to complete the do it now activity. Stick in your book.
Binary CSCE 101.
Presentation transcript:

Each column represents another power of the base TENs column ONEs column THIRTYTWOs col. EIGHTs column SIXTEENs col. FOURs column TWOs column ONEs column 42 101010 4 tens + 2 ones 128s column SIXTYFOURs col 01111011 THIRTYTWOs col. HUNDREDs column SIXTEENs col. EIGHTs column FOURs column TWOs column ONEs column TENs column ONEs column 123 -------- 1 hundred + 2 tens + 3 ones Write 123 in binary…

Convert from binary to decimal … Strategy: add weighted bits together. The weight at each position is 2^k at kth position, k = 0, 1, … from right to left 101011 = 1*2^5 + 1*2^3 + 1*2^1 + 1*2^0 = 32 + 8 + 2 + 1 = 43

110011 10001000 Convert these two binary numbers to decimal: 51, 136 32 16 8 4 2 1 128 64 32 16 8 4 2 1 Convert these two binary numbers to decimal: 110011 10001000 51, 136

28 101 Convert these two decimal numbers to binary: 11100 1100101 32 16 8 4 2 1 128 64 32 16 8 4 2 1 11100 1100101

You'll write these right! (-to-left) Lab 4: Computing in binary base 2 base 10 128 64 32 16 8 4 2 1 100 10 1 10001000 = 136 RIGHT-to-LEFT conversion to binary is surprisingly simple! numToBinary( N ) You'll write these right! (-to-left) binaryToNum( S ) And to represent binary numbers ? Strings! '11001101000101011101001001'

10 minute mark Binary operations

Do you remember this algorithm? It's the same! Add these two binary numbers WITHOUT converting to decimal ! 101101 1 529 1110 + + 742 Hint: Do you remember this algorithm? It's the same! 1271 You'll need to write a function to do this on hw4pr2!

Do you remember this algorithm? It's the same! MULTIPLY these two binary numbers WITHOUT converting to decimal ! 529 101101 * 42 Hint: 1110 * Do you remember this algorithm? It's the same! 1058 2116 22218

Shift happens... 42 420 11 110 def leftshift( s ): 100 10 1 42 def leftshift( s ): """ left-shift by one bit """ return s + '0' 420 What does left-shifting do to the value of a decimal number? 4 2 1 Multiplies by 10, 2 11 110 What does it do to the value of a binary number?

Python's shifts << >> 11 3 << 1 6 3 << 2 ? left-shift operator right-shift operator 4 2 1 left-shift by 1 11 3 << 1 6 left-shift by 2 3 << 2 ? 12 10 right-shift by 2 42 >> 2 ? But why?

You need to add two binary numbers You need to add two binary numbers. Let's first explore adding two decimal numbers… …but entirely as strings!

adding decimal strings e.g., S = '31' T = '11' def add10(s,t): """ adds the *strings* S and T as decimal numbers """ if len(s) == 0: return t if len(t) == 0: return s eS = s[-1] eT = t[-1] if eS == '0' and eT == '1': return add10(s[:-1],t[:-1]) + '1' if eS == '1' and eT == '1': return add10(s[:-1],t[:-1]) + '2' if eS == '2' and eT == '1': return add10(s[:-1],t[:-1]) + '3' if eS == '3' and eT == '1': return add10(s[:-1],t[:-1]) + '4' # Lot more rules - how many in all? the "end of S" - hence eS the "end of T" - hence eT One of the exercises in problem 2 requires adding binary. The lab mentions that we would discuss this in class. how about for hw4: addB?

carrying on 1 23 19 -- 2 4 def add10(s,t): e.g., S = '23' T = '19' def add10(s,t): """ adds the *strings* S and T as decimal numbers """ if len(s) == 0: return t if len(t) == 0: return s eS = s[-1] eT = t[-1] ... if eS == '3' and eT == '1': return add10(s[:-1],t[:-1]) + '4' # What if we have to carry? if eS == '3' and eT == '9': 1 23 19 -- 2 4 return add10(s[:-1],add10(t[:-1],'1')) + '2' how about for hw4: addB?

carrying on 1 23 19 -- 2 4 def add10(s,t): e.g., S = '23' T = '19' def add10(s,t): """ adds the *strings* S and T as decimal numbers """ if len(s) == 0: return t if len(t) == 0: return s eS = s[-1] eT = t[-1] ... if eS == '3' and eT == '1': return add10(s[:-1],t[:-1]) + '4' # What if we have to carry? if eS == '3' and eT == '9': return add10(? , ?) + '2' 1 23 19 -- 2 4 return add10(s[:-1],add10(t[:-1],'1')) + '2' What goes here??? HINT… you might need TWO calls to add10 how about for hw4: addB?

Representing a binary image Now, a word about hw4pr3… (25-)30 minute mark Representing a binary image

Representing a Binary Image Binary Images 11111111 00000000 Discuss binary images, 1 = white, 0 = black. Really one long string '1111111111111111000000000000000011111111111111110000000000000000' black is 0; white is 1

Representing a grey-level image number of columns number of rows Sample PGM File Each pixel (picture element) has a value from 0 to 255. PGM format Note: Displayed the image by making a 100 pixel by 100 pixel block for each value.

Digital Color Image The continuous picture is broken into a fixed grid of tiny squares (pixel) of same color and intensity. The right image exaggerates the detail of individual pixels. RGB – each pixel has three values from 0-255 for Red, Green, Blue. (0, 0, 0) is black; (255, 0, 0 ) is red; (255, 255, 255) is white y Note: you can see jpeg artifacts in right image. x

Digital camera with cover removed Don't try this at home! Tell them that digital camera have a computer inside that perform algorithms such as raw to jpeg compression.

Histogram of intensities Binary Data All data is binary… How about naturally ternary ? But some data is naturally binary! Original Image Histogram of intensities BINARY image

Hw4: binary image compression 10101010 01010101 Binary Image Encoding as raw bits just one big string of 64 characters "1010101001010101101010100101010110101010010101011010101001010101"

Hw4: binary image compression 00000000 11111111 00001111 Binary Image Encoding as raw bits just one big string of 64 characters If our images tend to have long streaks of unchanging data, how might we represent it more efficiently… (but still in binary)? "0000000000000000111111111111111100000000000000000000000000001111"

Hw4: binary image compression 0 is the first digit 1 is the next digit 1 is the final digit 00000000 11111111 00001111 0 is the next digit There are 16 of them. Again, there are 16 of them. There are 4 There are 28 0100001100000111001100 One possible idea problems?? Encoding as raw bits just one big string of 64 characters

fixed-width image compression a FIXED-width encoding is needed 0 is the first digit 1 is the next digit and so on… There are 16 of them. Again, there are 16 of them. 28 zeros 4 ones 8 bits for each "block" 00010000100100000001110010000100 1st bit holds 1 pixel value 7 bits: # of repeats 7 bits: # of repeats 7 bits holds the # of those values in a row 8-bit data block 8-bit data block 8-bit data block 8-bit data block 00000000 11111111 00001111 original data original image

If 7 bits holds the # of consecutive repetitions of data, what is the largest number of 1s or 0s that one block can represent? the pixel 00010000 7 bits? B bits? 7 bits: # of repeats 8-bit data block For hw4pr3, images will have up to only 121 pixels...

What function(s) might help here? hw4 pr3 def compress(anImage): """ returns the Run-Length-Encoding of the input binary image, anImage """ What function(s) might help here? def unCompress(compressedImage): """ returns the binary image from the Run-Length-Encoded, "compressed" input, compressedImage """ Can the display image from cs5png import * binaryIm(aImage, ncols, nrows)

45 minute mark Beyond Binary

Off base? Base 60 – Ancient Sumeria All this focus on 10 seems so alien! Base 60 – Ancient Sumeria Base 12 – "Duodecimal Society" "Dozenal Society" Echoes: dozen, gross -- show donzenal society pages: http://www.dozenal.org/index.php?u=31 http://www.polar.sunynassau.edu/~dozenal/ British units: 12 inches, 12 ounces (Latin: uncia) time: 12 hours 60: seconds, minutes, circular arcs -- from a 360 day calendar of the ancient sumerians and babylonians (circle of the sun going around the earth) base 20 -- even though there is no evidence in Europe… fingers + toes "four score and seven years ago" languages exhibit it: French Twenty (vingt) is used as a base number in the French language names of numbers from 60 to 99. So for example, quatre-vingts, the French word for 80 literally means "four twenties", and soixante quinze, the word for 75 is literally "sixty-fifteen."). Olmec base-20 number representation (East Mexico, 1200 BC-600 AD) Base 20 – America, precolombus Echoes of these bases are still bouncing around…

Beyond Binary 101010 42 base 1 base 2 base 10 digits: 1 digits: 0, 1 111111111111111111111111111111111111111111 digits: 1 101010 128 64 32 16 8 4 2 1 base 2 digits: 0, 1 number of digits?! base 10 42 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Beyond Binary 101010 42 base 1 base 2 base 3 base 10 111111111111111111111111111111111111111111 digits: 1 101010 128 64 32 16 8 4 2 1 base 2 digits: 0, 1 81 27 9 3 1 base 3 digits: 0, 1, 2 There are 10 kinds of "people" in the universe: those who know ternary, those who don't, and those who think this is a binary joke! base 10 42 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

and what are the bases of the others? Beyond Binary base 1 111111111111111111111111111111111111111111 digits: 1 101010 128 64 32 16 8 4 2 1 base 2 digits: 0, 1 base 3 1120 81 27 9 3 1 digits: 0, 1, 2 base 4 base 5 Which of these isn't 42...? base 6 222 60 54 46 39 base 7 base 8 and what are the bases of the others? Difficult to do in your head… a computer makes it easy! hw2pr2 base 9 base 10 42 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 base 11 base 12

Beyond Binary! 101010 1120 222 132 110 60 42 2A base 2 base 3 base 4 128 64 32 16 8 4 2 1 base 2 digits: 0, 1 1120 81 27 9 3 1 base 3 digits: 0, 1, 2 64 16 4 1 base 4 222 digits: 0, 1, 2, 3 125 25 5 1 base 5 132 digits: 0, 1, 2, 3, 4 216 36 6 1 base 6 110 digits: 0, 1, 2, 3, 4, 5 49 7 1 base 7 60 digits: 0, 1, 2, 3, 4, 5, 6 … 100 10 1 base 10 42 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 … 2A 256 16 1 base 16 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F Hexadecimal