1 / 65

Digital Representation

Digital Representation. Jim Williams HONP-112 Week 4. Flipping Coins. We know a binary digit only has one of two possible values. In the context of a coin toss, a coin also has only 2 possible values - heads (H) or tails (T)

gavivi
Download Presentation

Digital Representation

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Digital Representation Jim Williams HONP-112 Week 4

  2. Flipping Coins • We know a binary digit only has one of two possible values. • In the context of a coin toss, a coin also has only 2 possible values - heads (H) or tails (T) • If we flipped 2 coins together, how many different ways can they come up? • What about if we flipped 3 coins together? How many different possible combinations of H and T are there?

  3. Example: Flipping 3 coins • Each individual coin can come up in one of 2 possible ways (H or T) • If we flip 3 coins together, here are the possible combinations: • HHH, HHT, HTH, HTT, THH, THT,TTH,TTT • How many combinations is that?

  4. Why 8 Possible Combinations? • We can see that flipping 3 coins, each having 2 possible values, results in 8 possible combinations. • Why Is That? Because we must multiply together the possible number of values of each individual coin for each coin we are flipping.

  5. Multiply The Possibilities • We flip 3 coins. • Let’s multiply the possibilities for each: • 2 possibilities for coin 1 • x 2 possibilities for coin 2 • x 2 possibilities for coin 3 • We end up with 2 x 2 x 2 possible combinations, which is 8.

  6. Combination table • When dealing with a small number of coins we can easily create a table for all the possible combinations. • There are three coins so we will have 3 columns. • We know the total number of combinations we will have (8). • So for the first column, split the result in half – 4 rows of tails, 4 rows of heads. • Note: By convention we usually start the lists with the “0” value – in this case the “tails”.

  7. Combination table – 3 coins

  8. Combination table • Now in the next column, instead of groups of 4, divide that in half so you are working in groups of 2 instead. Alternate T and H as shown :

  9. Combination table – 3 coins

  10. Combination table • Now in the next column, instead of groups of 2, divide that in half so you are working in groups of 1 instead. Alternate T and H as shown :

  11. Combination table – 3 coins

  12. Combination table • As you can see the general rule for the combination table is: • First column: Alternate the Tails/Heads (0/1) values in groups of half of your total number of combinations. • Each subsequent column: Alternate the Tails/Heads (0/1) values in groups of half of the size of the group from the previous column.

  13. Combination table • In our example of three coins: • We had 8 possibilities • So, First column: Groups of 4 (8/2): 4 rows of heads, 4 rows of tails. • Second column: Groups of 2 (4/2) – alternating groups of heads/tails • Third column: Groups of 1 (2/2) – alternating groups of heads/tails • Try a combination table of 4 coins now.

  14. Double the possibilities • When we had three coins, there were 8 combinations of tails/tails. • As you can see, if we add just one more coin, we now have 16 possible combinations of tails/heads. • If you are observant … you will notice we are really adding a column to the left of the existing table – 16 rows long, now we have 8 rows of tails and 8 rows of heads • Leave the old table where it is (next to the 8 tails in the new column), and make an entire copy of it in the remaining “empty” rows nest to the heads in the new column!

  15. 4 coin table – first half

  16. 4 coin table – second half

  17. Double the possibilities • Likewise, if we added another coin, we would double the combinations to 32, and so on. • The possible combinations therefore will increase exponentially (where the exponent is a power of 2 of course) with each single bit added to the mix! • Consider this for a moment – would you rather receive a million dollars, or a penny one day and the amount doubled each day for a month? • The next time you hear the much overused/misused phrase “increasing exponentially”, keep this in mind and see if someone saying this REALLY means it :-)

  18. Mathematically speaking… • For our 3-coin example, our total number of possible combinations was 2 x 2 x 2. • Does this look familiar? It is 2 to the 3rd power, or 23 • Since a coin has only 2 possible values, the general formula for the number of possible of combinations is 2n • n=number of coins

  19. In terms of BITS • So based on our understanding of the coin examples, we can apply the same rule to working with Bits: • Given n number of bits: the resulting number of bit pattern combinations is 2n • This principle (and its “inverse” discussed later) is the most important thing you need to understand for this lesson, and for this entire course!!!

  20. What do the combinations mean? • What the bit pattern combinations mean is dependent on the context. • But it is important to understand that it is each distinct PATTERN of binary digits that will then be “assigned” to represent a distinct value in human terms.

  21. Maybe they represent…

  22. Or maybe…

  23. What do the combinations mean? • As you can see the meaning is arbitrary and depends on the list of distinct values I want to find a digital bit pattern to represent. • Notice that I “mapped” a list of distinct values to distinct bit patterns. • Also notice that in both cases the list was of 7 items, (do you know what they were?) , so I was left with one pattern I did not use. That is fine, and which one to “ignore” is again up to the designer of a system. • Remember that this “mapping” is conceptual. We will see an real-life example later on. For now you need to understand the concept.

  24. A known number of Combinations • What if we already know how many combinations we WILL need • For instance we know we want to have 30 possible patterns? • We know that 2n = number of patterns • So try to work it out in reverse and get the smallest possible whole number value for n • Example: 30 = 2n. Solve for n; but n must be a WHOLE NUMBER.

  25. Bits needed to represent a number of patterns • We know that we need n bits to represent 2n different possible patterns. In our example we have 30 possible bit patterns. • Let’s try to come up with a number of bits that works. • 4 bits = 24 combinations = 16 (not enough) • 5 bits = 25 combinations = 32 (enough) • This is “trial and error” but it works and I recommend you use this method to solve these types of problems. The “technical” way is on the next slide – for informational purposes only…

  26. Bits needed to represent a number of patterns – technically speaking • If we already know we need x number of combinations, the “technical” answer to our question of “how many bits do we need” is the base-2 logarithm of the number of combinations. • In other words, what power do we need to raise 2 by to get the number of patterns? • But in cases where the number of needed patterns is not a whole power of 2, we would have to round up the base-2 logarithm to the next whole number anyway. So use the simpler “trial and error” method instead!

  27. Review – bit and pattern calculations • If we have a given number of bits (n), know how many possible patterns we have. • Be able to write out the patterns. • Conversely, if we already know how many patterns we will need, then know how to find the smallest possible number of bits so that 2n gets us an answer greater than or equal to the number of patterns.

  28. What does “Digital” mean? • The term “digital” means that we are dealing with electronics that only understand two distinct “states” – high/low, on/off, 1/0, etc. • Therefore anything we wish to represent digitally must be converted to various patterns of 1/0. • The computer will “understand” what these patterns mean and handle them accordingly.

  29. What does “Analog” mean? • Analog means that we are dealing with electronics that can understand an infinite number of “states”, or values. • Unlike digital signals and media (consisting only of discrete values), analog technology can reproduce a continuous set of values.

  30. Analog vs. digital: Example • An analog way to represent music is a phonograph record. • Grooves cut into the record is analogous to the sound waves of the music. A record groove is a continuous line, and there are an infinite number of points on a line. • A digital way to represent music is an audio file. • But we cannot store an infinite number of values, so instead of a “line” we have many discrete “points” instead, each containing a set number of digits which represent different values.

  31. Analog vs. digital signals on a scope • See below. Notice the digital signal only has two possible values. FYI it is not really a continuous line. But it appears that way because there are more changes per second than the scope can show (you don’t have to know what all that means…)

  32. Representation • Remember that neither analog nor digital is “reality.” • For instance, a 35mm film photograph (analog), or a JPEG file of a picture (digital) is not REALLY the scene you captured. • Both are only representations of that reality. • Keep this point in mind throughout the rest of this course.

  33. Digital Representation • We now know that a computer works exclusively with binary numbers. • In other words, it must understand human information in terms of digital electronics (“on” or “off”) • Digital Representation - or digitizing - is when we represent human information as binary digits.

  34. How do we Digitize Information? • A computer has its own set of “rules” about how different kinds of information may represented digitally. • These rules may be different for different types of computers. The designers of a computer make the decision about how this is done. • We will not get into the technical aspects of how this is done yet – but we will study the functional/analytical aspects.

  35. What can we digitize? • Almost any piece of human information can be digitized. • Books, papers, and other written works • A checkbook register • Customer purchase records • Music • Photographs • etc.

  36. What We Need • Several things are necessary to come up with a way to digitize human information: • 1. An full understanding of what the information is • 2. Finding the smallest meaningful piece of information that the rest is built upon. • 3. How many possible “values” the smallest meaningful pieces of information can have. • After we know this, we can design a way to represent each of these different values using combinations of bits. • Then string them all together to have a complete representation of the full set of information (photo, written document, song, etc.).

  37. Smaller Is Better • When digitizing, we must think of our information in the smallest possible terms. • Then, we can find a way to digitally represent each small piece of information. • Combining these small digital representations gives us our complete digitization of the whole information.

  38. Understanding Information • This step is the most important, and has nothing to do with computers. • In the next few slides, we will try to break a piece of information into its parts. • Then, we can see what we need to do to digitize the information.

  39. Analysis • As you can see the most important part of designing a way to digitize information is the analysis phase. This is where we do our thinking, discovery, and understanding of whatever it is we are trying to digitally represent. • For instance, if we were developing a way to digitally represent musical notes, and did not know how many musical notes there were, we would fail.

  40. Information Example • Let’s take a piece of human information we should all be familiar with – the written word (i.e. a paper, book, article, etc.). • We want to come up with a way to represent this type of information in a digital form. • Think a while - what does a written paper consist of?

  41. Written Paper - The Basics • Assume the paper is written in the English language. • A written paper consists of paragraphs. • Each paragraph consists of sentences. • Each sentence consists of words. • Each word consists of letters. • We cannot break the written word down any further than this. (A letter is not built up out of anything smaller.) • So, let’s start with finding out how many possible “values” a letter has.

  42. How Many Letters? • We have to allow for any possible letter to be used in the paper. • The English language consists of 26 different letters. • However, each letter can be of upper or lower case. So now we have to account for 52 different letters.

  43. So Far, So Good? • So far, we have determined that we have to account for 52 different letters. • We will ignore other things that may be in a written paper for now (can you think of any?) • If we can figure out a way to digitize each letter, then we can put them all together and digitize the entire paper.

  44. Digitizing our Letters (characters) • We must come up with a way to digitally represent a single small piece of information in 52 different possible ways. • Remember - this means that we represent the information using binary digits (bits). So we need to define 52 different PATTERNS of 1s and 0s – and each of these patterns will be “assigned” to each of the corresponding possible values. • How many bits do we need to do this?

  45. Bits needed to represent our Letters • We know that we need n bits to represent 2n different possible values. We have 52 possible values for each letter. • Let’s try to come up with a number of bits that works. • 4 bits = 24 combinations = 16 (not enough) • 5 bits = 25 combinations = 32 (not enough) • 6 bits = 26 combinations = 64 (this works!)

  46. Our Letters can be Digitized • We determined that there are 52 possible values for a single letter. • We also discovered that we need 6 bits to represent these 52 possible values. • With this information, we can now represent our human information (letters) as binary digits that the computer can understand. • We will take the bit patterns and assign them to each possible value for a letter. • Of course, the computer must be “told” how to interpret the patterns.

  47. In Reality... • Of course, in real life, there are other characters besides letters • punctuation marks, spaces, tabs, page breaks • Number characters • other “odd” characters (Greek letters, etc.) • So most computers use a sequence of 8 bits to represent characters - allowing for 256 (or 28) different values. • Research the “Extended-ASCII” chart. It shows the real 8-bit patterns that are assigned to characters. Of course the computer is designed to understand this scheme.

  48. In Reality... • Originally only 7 bits were used per character (the original ASCII scheme). • Then one extra bit was added, and this doubled the total number of possible patterns from 128 to 256 (remember about increasing exponentially??). • Maybe you still don’t think 256 possible characters is enough patterns??? • Others have addressed this – see “Unicode” for more information.

  49. Bits and Bytes • As you know, a bit is a single binary digit. • In computers, we sometimes think of a group of 8 binary digits as a single binary number. • A group of 8 binary digits is called a Byte. • A byte example: 10010101 • Most of the time, we measure things in Bytes, not bits.

  50. Bits and Bytes • So one can say that characters in most modern computers are represented by a one-byte code (as opposed to 8-bit code). • Sometimes you will see things referred to in terms of bytes, and other times you will still see reference to bits instead (especially when marketing people want their computer’s features to appear “bigger”). • Just know that there are 8 bits to a byte, or conversely there are 1/8 bytes to a bit. • Example: I have a 24-bit pattern, please express this in bytes. • Example: How many bits are contained in a 4-byte pattern?

More Related