INFORMATIONAL COMMUNICATION TECHNOLOGY Laboratory work 1 Data Representation Using Binary Digits A piece of data, such as an alphabet letter, may be represented using a sequence of binary digits0's and 1's. There are several types of codes used to represent character data. For example, using extended ASCII (America Standard Code for Information Interchange) code, the alphabet letter "a" can be represented using a series of eight binary digits, "01100001." Each binary digit is called a bit. And, eight bits is one byte. Extended ASCII code uses eight bits (or one byte) to represent input characters. Below are binary representations of characters in extended ASCII code. Figure 1 ASCII code All data, including audio, visual, and program instruction data can be represented and stored using a sequence of binary digits, or a sequence of bytes. Recall that a file is a collection of data. In some files, the bits of data directly encode individual letters, numbers, and punctuation symbols that make up words and sentences. In other files such as an image file, the bits of data need to be computed in order for them to transform to images that we can interpret. Most applications such as Microsoft Word or PowerPoint encode information in specialized ways that are not readable by humans. Thus, even though Microsoft Word is often used to edit text, a Word document cannot be properly displayed by a simple text editor like Notepad because the document includes information in a format specific to Microsoft Word. Therefore, it must be opened by Microsoft Word to be read. Some files have a header section that indicates which format was used to encode the data in order to allow the computer to reassemble the binary data back into the human-readable form of the document. Increasing Need for Bytes In the late 1970s and early 1980s, inexpensive personal computers were manufactured for the first time, and soon a large consumer market developed. At first small amounts of memory such as thousands of bytes were all that was needed to handle the simple spreadsheet and word processing tasks. But, before long, users wanted software to allow them to do more tasks such as creating drawings and generating complex page layouts. As consumer demand grew, computing requirements also grew. This demand led to new developments that expanded memory capacities. By the mid 1980s, memory was up to millions of bytes. Today, office and home computers often have billions of bytes in memory capacity. Memory for data-intensive systems, such as the Geographic Information System (GIS), require trillions of bytes. Below is a chart illustrating the storage capacity over the years since the 1970s with their associated prefix and abbreviation. Decade 1970s 1980s 1990s 2000s Order of magnitude in Thousands Millions Storage capacity Billions Trillions Prefix Kilo (103) Mega (106) Giga (109) Tera (1012) Abbreviation K M G T In terms of storage, more is better—which means more information in the form of both data and programs that act on that data can be stored. Corresponding to the growth in storage capacity, memory capacity is also increasing. Moreover, memory technologies are getting smaller, lighter, and faster, for about the same price. You will learn more about storage and memory technologies in the next unit of this course. 1.3.2 Number Systems ● Decimal ● Binary ● Hexadecimal The world of computing uses several number systems to represent data. While the decimal system, also known as base10, will be familiar to people, as it is the numbering system used in everyday life, binary (base2) and hexadecimal (base16) are common number systems used in computing today. Decimal We will start our discussion on number systems by examining the decimal system as an example of a number system. The decimal number system contains ten values- 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Each number in the decimal number system can be broken into digits by their "place" in the number. Using the number 43,872 as an example, 2 is in its 0th place, 7 is in its first place, 8 in its second, 3 in its third, and 4 in its fourth. Each place has a value that can be represented either exponentially or by its decimal values. The following table shows the exponential and decimal representation for each place in the number 43,872. Place 4th 3rd 2nd 1st 0th 4 3 8 7 2 Digit 4 3 2 1 10 10 10 100 Exponential value of the place 10 10,000 1,000 100 10 1 Decimal value of the place Table 1 Exponential and decimal values corresponding to a digit's place in a number Note that the exponential values are raised to a power corresponding to the place of the digit. For example, the exponential value of the 4th place is 104. To determine the value of the number, multiply the digit contained in a column by the value that column represents. The following is a sample calculation for the previous example. 4 × 104 + 3 × 103 + 8 × 102 + 7 × 101 + 2 × 100 = 4 × 10,000 + 3 × 1000 + 8 × 100 + 7 × 10 + 2 × 1 = 40,000 + 3000 + 800 + 70 + 2 = 43,872 While performing these calculations on a decimal number seems trivial, it demonstrates a pattern, or formula can be used to convert a number in any numbering system to decimal. dp(b)p + dp-1(b)p-1 + . . . + d0(b)0 Where p is the place, b is the base, dp is the digit in the highest place in the number, and dp-1 is the next highest place in the number, and so on. Using the number example above, dp = 4, dp-1 = 3, b = 10, and p = 4. 4 × 104 + 3 × 103 + 8 × 102 + 7 × 101 + 2 × 100 = 43,872 The formula above can be used to compute the decimal value of any number in a given base. Below is the calculation for converting 214 to its decimal value (from base 4 to 10): Place 1st 0th 2 1 Digit 1 4 40 Exponential value of the place 4 1 Decimal value of the place Table 2 Exponential and decimal values corresponding to a digit's place in a number 2(4)1 + 1(4)0 = 2× 4 + 1 × 1 = 8 + 1 = 9 Binary Since all numbering-systems are treated the same, you already have all the tools necessary to convert to and from binary. Let's review converting from binary to decimal the number 101101102. The highest place, p, is obtained by counting the number of places in the binary number, starting from zero. In this case, p = 7. 1 × 27 + 0 × 26 + 1 × 25 + 1 × 24 + 0 × 23 + 1 × 22 + 1 × 21 + 0 × 20 = 1 × 128 + 0 × 64 + 1 × 32 + 1 × 16 + 0 × 8 + 1 × 4 + 1 × 2 + 0 × 1 = 128 + 0 + 32 + 16 + 0 + 4 + 2 + 0 = 182 For example, in 1001102 the largest place is 2p, where p = 5. Because binary is the easiest numbering system to convert into decimal, it will help us later when we are convert hexadecimal numbers. Hexadecimal You should notice that it takes more digits to express a value in binary notation than in decimal notation. For example, the number 99 in decimal is 1100011 in binary. Computer professionals have adopted hexadecimal notation as shorthand for binary so that they can express binary values more concisely. Hexadecimal (base16), or "hex," is most likely the largest numbering system that you will work with. In the modern decimal system, the Arabic number set 0-9 has to be supplemented by additional values to represent the decimal equivalents of 10, 11, 12, 13, 14, and 15. Instead of inventing new symbols to represent these numbers, the letters A-F are used. Hexadecimal is represented by the set of numbers 0-F. While both lower case and upper case letters can be used in hexadecimal for A-F. In this course, we will use upper case A-F. Hexadecimal, however, is not usually represented by appending a 16 as a subscript to the number. There are two differing formats for representing hexadecimal numbers: prepending 0x or appending h. We will use 0x to denote hexadecimal numbers. Given: 4A3F16 to Decimal There are two methods for converting hexadecimal into decimal. There is the direct approach using the formula: p + dp-1(b)p-1 + . . . + d0(b)0 p(b) Where dp is the digit in the highest place in the number, and dp-1 is the next highest place in the number, and so on. b is the base and p is the value of the highest place. The conversion is as follows: 4 × 163 + A × 162 + 3 × 161 + F × 160 = 4 × 4096 + 10 × 256 + 3 × 16 + 15 × 1 = 16,384 + 2560 + 48 + 15 = 19,007 This method is particularly useful for larger hexadecimal numbers. However, for smaller numbers of one or two digits, it is often faster to convert the hexadecimal number to binary before converting it to decimal. Hexadecimal maintains a relationship with binary as it is a derivative of a base2 system. Each hexadecimal digit represents four binary places. The chart below shows the relationship between binary, hexadecimal, and decimal for 0x0-0xF. Decimal Binary Hexadecimal 0 0000 0x0 1 0001 0x1 2 0010 0x2 3 0011 0x3 4 0100 0x4 5 0101 0x5 6 0110 0x6 7 0111 0x7 8 1000 0x8 9 1001 0x9 10 1010 0xA 11 1011 0xB 12 1100 0xC 13 1101 0xD 14 1110 0xE 15 1111 0xF Table 5 Decimal, binary, and hexadecimal conversions Let us convert 0x3B to decimal via binary. The first step is to find out what the individual hexadecimal number represents in binary. Replace the hexadecimal number with the binary number. Therefore, 0x3B becomes 001110112. As you may recall from the previous section on binary, converting numbers from binary to decimal is much easier than with other systems, since multiplying by binary digits of 0 and 1 are trivial. 0x3B= 001110112= 32 + 16 + 8 + 2 + 1 = 59 A byte of data (eight bits) can be written as just two hex digits. For example, the character "N" in extended ASCII code has the binary representation 01001110. If we write this as two groups of four bits each, we get 0100.1110. Using table 5 above, we find that 0100 is 0x4 and 1110 is 0xE. Therefore, the corresponding hexadecimal code for 0100.1110 is 0x4E. When setting up or maintaining a computer system, you will sometimes encounter hexadecimal numbers as representations of memory addresses, network addresses, or other hardware-related qualities. You may encounter them in operating system-related contexts as well, such as when a machine "crashes" and displays a failure report. Examples Binary to Decimal: Convert the binary 1001012 to its decimal equivalent: [(1) x 25] + [(0) x 24] + [(0) x 23] + [(1) x 22] + [(0) x 21] + [(1) x 20] [1 x 32] + [0 x 16] + [0 x 8] + [1 x 4] + [0 x 2] + [1 x 1] = 3710 The decimal equivalent for binary 1001012 is 3710. Decimal to Binary: Hexadecimal to Decimal: Convert 4B5A16 to decimal: (4 x 163) + (11 x 162) + (5 x 161) + (10 x 160) = 1929010. Decimal to Hexadecimal: Convert 6502910 to hexadecimal: Exercise 1 Question 1. Decimal, binary, and hexadecimal conversions a. Complete the following chart by converting the numbers given in one of the notations to the other two. Show calculations. Binary 101 0101 110 0110 11111010 10101111 Decimal 102 15 175 438 936 Hexadecimal 0x 55 0x F 0x FA 0x1B6 101010111100 298 b. What is the minimum number of bits that can be used to represent the decimal number 213? (Hint: convert 213 to binary.) c. What is the minimum number of bytes that can be used to represent the decimal number 213? d. What is a purpose of using hexadecimal notation? e. What is ASCII code? American Standard Code for Information Interchange Question 2. Data Representations in a Computer System Computer systems are made up of electrical components that are either on, or off, representing 1’s and 0’s, also called binary numbers. All data, such as numbers, are converted into binary representations in the computer system. The Extended ASCII chart below shows characters and their binary representations. Use the chart below and a calculator to answer the following questions: Figure 1 ASCII code You can obtain the binary representation of a word by concatenating the ASCII values of each letter. For example, “SSD2” in binary representation is 01010011 01010011 01000100 00110010. Exercise 2 a. “Fun” in binary representation is ____________. b. “Play” in binary representation is ____________, which is equivalent to _________ in decimal representation. c. 01100011 01100001 01110010 01100101 01100101 01110010 01110011 is the binary representation of the ASCII string __________. d. 0x7374617274 is a hexadecimal representation of the ASCII string __________. e. 1751478885 is the decimal representation of the ASCII string ___________. Additional Tasks: Number conversion to binary Decimal 89 Hexadecimal 3B Decimal 2016 Decimal 3108 Decimal 310816