
Bits and Bytes Computers are used to store and process data. Processed data is called information. You are used to see or hear information processed with the help of a computer: a paper you’ve just typed using Microsoft World, a digital photograph, a MP3 song you’ve downloaded on the Internet, etc. But how is the data stored in the computer? Whatever the medium in which it is stored, the most fundamental piece of data is always represented by a “two-value system”: low or high voltage, positive or negative polarity of a magnetic medium, absence or presence of “bumps” on a CD or DVD… These two values are logically represented by the digits 0 and 1. This is called a binary representation. Usually, the digit 0 is interpreted as the low value or absence of some kind of signal (such as no bump) and the digit 1 is interpreted as the high value of presence of some kind of signal. In other word, we encode the physical signal with the logical binary representation. This 0 or 1 digit is called a bit (short for binary digit). Obviously, just one bit cannot give much information since there are only two possible values. Hence, to store more useful data we must combine bits. However, even combining several (even many) bits will only give a finite numbers of possible objects. For example combining four bits gives the sequences 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111. These sixteen sequences can be selected to represent any sixteen objects of our choice but only sixteen objects. So if we want to represent integers, we can decide they represent the integers 0 to 15; if we represent letters they could represent the letters a, b, c, d, e, f, g, h, i, j, k, l, m, and n (or any other combination of sixteen letters of our choice); if we represent colors they could represent 16 predefined colors of our choice. We say that the data stored on a computer, and represented logically by combinations of bits, is discrete: it is finite and made of separable units. Analog versus digital Many different kinds of data can be represented in a computer: • numbers: whole numbers, positive and negative integers, real numbers; • text: made of letters, characters, digits; • audio: speech, music, sound tracks; • images and graphics; • video, etc. Some of these data types, such as text or integers on a bounded range, are discrete and it will be rather straightforward to convert these data to a binary representation that can be stored in the computer. But most data is analog, which means that it is continuous in nature. Let’s look at some examples. Pictures Continuous in space Infinite number of colors Sound Continuous in time Infinite number of frequencies 1 Real numbers Continuous even if bounded: always a number between two given numbers Because most data is analog, it must be broken in discrete pieces and those pieces must be represented by a binary representation to be stored in the computer. When this process is performed, we say that we digitize the data. Note that because digitizing data transforms continuous infinite data into finite discrete data, some data will be lost. For example we cannot really represent all the colors of the color spectrum, we cannot represent all the real numbers between 0 and 1. In this unit of the course, we will study how some types of data are represented and discuss some of the issues that arise from the conversion from analog to digital data. We will also use some tools to manipulate data. Binary Numbers Because the representation of more complex data such as sound or color is based on the representation of quantities (i.e. numbers), we must start our study with the representation of whole numbers. As seen above the sixteen first whole numbers (0 to 15) can be represented by all possible four-bit sequences. We will generalize this to longer bit sequences, but we will show how to derive a meaningful way to convert from a decimal number (the “regular” number) to a binary number and vice versa. The number system we use is the number system in base 10. Base 10 number system We use 10 digits, 0 to 9. In a number, the value of each digit depends of its position in the number. Each position corresponds to a value that is a power of 10. Table 1 shows the decomposition of the number 2324 in the number system of base 10 (also called decimal number system). 2 3 2 4 2⋅103 3⋅102 2⋅101 4⋅100 thousands hundreds tens units Table 1 This can also be written as . Base 2 number system The binary number system is the number system in base 2. We use 2 digits, 0 and 1, and each position in a number corresponds to a power of 2. Table 2 shows the decomposition of the binary number 1110 in the number system of base 2. 1 1 1 0 1⋅23 1⋅22 1⋅21 0⋅20 eights fours twos units Table 2 Therefore the value of the binary number is . When necessary, to avoid confusion we will append the subscript 2 to binary numbers. So the equality means that the number with binary representation 1110 is the same as the number with decimal representation 14 (we obviously cannot write 1110 = 14!). 2 We can check that the 16 sequences given in page 1 do match the decimal numbers 0 to 15 according to our definition. Binary Number Decomposition in sum of powers of 2’s Decimal Value 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 10 1011 11 1100 12 1101 13 1110 14 1111 15 Table 3 We can notice the pattern: , , , . In general, , where n is the number of zero following the 1. This is, of course, consistent with the definition of the binary number: there are n + 1 digits; each digit in this binary number corresponds to a power of 2, from for the left-most digit to for the right-most digit; all powers of 2’s except the left most ( ) are multiplied by 0. Recreation: Magic cards1 A magician has four magic cards; each card holds eight numbers between 1 and 15. 1 3 5 2 3 6 4 5 6 8 9 10 7 9 11 7 10 11 7 12 13 11 12 13 13 15 14 15 14 15 14 15 Blue Green Red Yellow She instructs each member of the audience to choose a number between 1 and 15 and hands out the cards to one person at random. The selected person returns only the cards that contain the number she/he had chosen (and kept secret). The magician guesses the number chosen. Suppose for example the person hands out the blue, green and yellow cards. Then the magician says “Eleven”! And she is right! How does this work? The cards are based on the binary representation of the numbers 1 to 15. The blue card contains all the numbers that have a 1 as right-most bit (i.e., the bit that corresponds to the units). The green card 1 Adapted from Aha! by Martin Gardner (1) 3 contains all the numbers that have a 1 as second digit from the right (i.e., the bit that corresponds to 21). The red card contains all the numbers that have a 1 as the second digit from the left (i.e., the bit that corresponds to 22 = 4). And finally the yellow card contains all the numbers that have a 1 as left-most digit (i.e., the bit that corresponds to 23 = 8). So, in our example, when the magician is given the blue, green and yellow cards, he knows that the number is 1011 in binary and therefore 8 + 2 + 1 = 11 in decimal. Note that the magician does not have to know binary numbers; she just needs a clever aide who made the cards for her! She just has to add the number that is at the top left corner of the cards that the member of the audience gave her. Exercises: all about patterns… 1. Table 3 shows clearly that the larger the number the more bits are needed to express a number in its binary representation. For example, 6 can be expressed with only 3 bits: 1102 but 12 cannot since 12 is 11002. It is permissible to add or remove leading zeros (i.e., zeros with no 1’s to their left), but it is not permissible to remove any other digits from the binary representation without altering its value. This is similar as 01060 being the same as 1060 in the decimal number system, but certainly different from 0106 or 0160. With one bit we can express just two numbers 0 and 1. a) Observe table 3. How many numbers can be represented with 2 bits? with 3 bits? with 4 bits? b) You should get a pattern in question a). From it, can you deduce the number of numbers that can be represented with 5 bits? with 8 bits? with n bits? 2. Observe table 3. Explain how you can distinguish between even and odd numbers if you are given just the binary representation. 3. If you observe the Binary Number column of table 3 you can imagine that this column is split into 4 columns: the column of the first digit (corresponds to the eights), the columns of the second digit (column of the fours), etc.
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages17 Page
-
File Size-