Module 2.1 Data Representations In Computer Systems PDF
Document Details
Uploaded by GreatLyric
Davao del Norte State College
Tags
Related
- 01-01- تمثيل البيانات (11-23) PDF
- Binary Number System Explained
- Chapter 1 Data Representation & Digital Logic PDF
- Computer Systems 245 Lecture Notes PDF
- Computer Organization and Architecture Lecture 2: Data Representation - Fall 2024 - Mansoura University PDF
- Data Representation Inside Computer PDF
Summary
This document provides an introduction to data representations in computer systems. It details positional numbering systems, conversions between different number bases, and the representation of signed integers and floating-point numbers. The document also contains learning objective, time frame, topics covered, and exercise sections.
Full Transcript
## **2** DATA REPRESENTATIONS IN COMPUTER SYSTEMS ### Objectives At the end of the module, the students are able to: * Demonstrate proficiency in converting number bases and typical numeric representation techniques. * Employ adeptness in translating decimal to floating-point representation. ###...
## **2** DATA REPRESENTATIONS IN COMPUTER SYSTEMS ### Objectives At the end of the module, the students are able to: * Demonstrate proficiency in converting number bases and typical numeric representation techniques. * Employ adeptness in translating decimal to floating-point representation. ### Topics covered * Positional Numbering Systems * Decimal to base-n conversions * Signed Integer representation * Floating-point representation ## **LESSON 1** POSITIONAL NUMBERING SYSTEMS AND DECIMAL TO BASE - n CONVERSIONS ### LEARNING OBJECTIVES: * Demonstrate proficiency in converting number bases and typical numeric representation techniques. ### TIME FRAME: 5 hours The organization of any computer largely relies on how it denotes numbers, characters, and control information. Standards and conventions established over the years have determined certain aspects of computer organization. The most basic unit of information in digital computers is called a bit, which is a contraction of binary digit. A bit is equivalent to "on or off" or "high and low" or "1 or 0". Old mainframe computers created a standard of using 8 bits as a basic unit of addressable computer storage, commonly known as a byte. A half of a byte is called a nibble. It is used since each bit in a byte has value within a positional numbering system. The nibble with most significant bits is called a high-order nibble while the other half is called a low-order nibble. Computer words are consists of two or more adjacent bytes usually manipulated and addressed. Word size refers to the data size that is handled by a specific architecture. Words can be 16-bits, 32-bits, 64-bits. In this lesson, we will learn the various ways in which computers can store and manipulate numbers and characters. Let's get started! ### ACTIVITY #### COUNT THE DOTS! One side of the card contains dots while the other side has nothing. Each card has a different number of dots as shown in the picture below. Instruction: A dot represents 1 bit. You need to create a sequence of cards to determine the number it represents (based on the number of dots). When the card is flipped and dots are not showing, it represents zero; otherwise, it represents the 1. For example, **[Image of 5 cards, each with a different number dots: 11111, 00000, 00000, 11111, 11111. Below the cards it says '1 0 0 1 1 = 19']** Create a sequence of cards based on: 1. Day of the month you were born. 2. Your age. 3. Your best friend's birth month. ### ANALYSIS Based on the activity you did, answer the following questions: 1. What is the largest number the cards can represent? 2. What do you notice about the number of dots on the cards? 3. How many dots would the next card have if we carried on to the left? ### ABSTRACTION In a positional number system, the fundamental numeric value is governed by the position the number holds and not by the number itself. For example, the number 528, 5 is worth more than 8. Why? Because of the respective position within a number. The general idea behind the positional numbering system is that a numeric value is represented through increasing powers of a radix (or base). This is frequently referred to as a weighted numbering system since each position is weighted by a power of the radix. The decimal system has a base of 10, the binary number system has a base of 2, and the hexadecimal number system has a base of 16. The set of valid numerals for a positional numbering system is equal in size to the radix of that system. For example, there are 10 digits in the decimal system, 0 to 9, and 2 digits in the binary system, 0 and 1. The largest valid number in a radix system is one smaller than the radix or n -1. So for base-8, the largest number that we can assign to a numeral is 7 and not 8. To distinguish among numbers in different radices, we use the subscript, such as 12810 to represent decimal number 128, 478 to represent 47 in octal. Within the decimal system, it works like this (start the segmentation from the rightmost integer): | Base and Exponent | Weight | |---|---| | 103 | 1000 | | 102 | 100 | | 101 | 10 | | 100 | 1 | Applying this on 15710: | Base and Exponent | Weight | Segmented number | |---|---|---| | 102 | 100 | 1 | | 101 | 10 | 5 | | 100 | 1 | 7 | In this example, 1 will be multiplied by 100, 5 will be multiplied by 10, and 7 is multiplied by 1. To get the decimal value of a number, we will still get 157 since the given is already in a base-10 or decimal system, which is the most common numeral system we use. For base-2 or binary, we will use the table below. | Base and Exponent | Weight | |---|---| | 23 | 8 | | 22 | 4 | | 21 | 2 | | 20 | 1 | Applying this on a nibble 1011 base-2 or 10112: | Base and Exponent | Weight | Segmented number | |---|---|---| | 23 | 8 | 1 | | 22 | 4 | 0 | | 21 | 2 | 1 | | 20 | 1 | 1 | By following the same method we did a while ago, (8 x 1) + (4 x 0) + (2 x 1) + (1 x 1) = 1 10112 is equivalent to 1110. It is one-way to convert binary to decimal numbers. Let us apply the same procedure to the following radix: * 7368 = (7 x 82) + (3 x 81) + (6 x 80) = 47810 * 20113 = (2 x 33) + (0 x 32) + (1 x 31) + (1 x 30) = 2210 * 1FA816 = (1 x 163) + (15 x 162) + (10 x 161) + (8 x 160) = 8, 10410 Notice in the third example, letters A and F were used. The hexadecimal system utilizes letters A to F to represent numbers 10 to 15 in the decimal system. The most important radices that were used in the computer system are binary and hexadecimal. The octal system is used occasionally. However, for this lesson, we will be using different radices to train ourselves to convert numbers to different radices. ### Numeric conversion between number bases What we have learned a while ago is one of the methods of converting base-n (n represents the radix) numbers to the decimal system. Aside from the weighted numbering system, an alternative method can be used to convert from other bases to base-10. The technique is also computationally simple; starting from the most significant (leftmost) digit, we multiply by the base, n, and add the next digit to the right. We repeat this process until the least significant digit has been added. For example, convert 27168 to base-10. 2 x 8 = 16 + 7 = 23 23 x 8 = 184 + 1 = 185 185 x 8 = 1480 + 6 = 148610 If you count the number of times that each digit in this example is multiplied by the base number, in this case, 8, you discover that the leftmost digit is multiplied by 8 four times, or 84, and that each successive digit is multiplied by 8 one less time, until you arrive at the rightmost digit, which is not multiplied by the base number at all. Thus, each digit is multiplied by its proper weight, and the result is what we would expect. Let us try to convert the following radix to base-10 using the alternative method. * 4235 = (4 x 52) + (2 x 51) + (3 x 50) = 11310 * A1216 = (10 x 161) + (1 x 160) + (2 x 16-1) = 257810 You have been presented to two different methods for performing conversion from base-n to base-10. Now let us discuss the other way around, converting base-10 to any radix. The weighted numbering system can be used. However, we need to find the value corresponding to the weight of each digit such that the total will add up to the base-10 number that we are trying to convert. This provides a simple methodology for the conversion. Start with the digit whose weight is the largest possible without exceeding the number to be converted. Determine the largest value for that weight that does not exceed the number to be converted. Then, do the same for each successive digit, working from left to right. For example, convert 29410 to base-8. | Base and Exponent | Weight | Octal number | |---|---|---| | 83 | 512 | 4 | | 82 | 64 | 4 | | 81 | 8 | 6 | | 80 | 1 | 6 | Evidently, 512 digit is too large compared to the given, so the expected result will be a 3-digit octal number. The number 64 can fit the 294 quadruple times, also, if we multiply 64 and 4 the result is 256, thus, the first digit is 4 and the remaining 38 (the difference between 294 and 256) needs to convert. The number 8 can fit the remaining 38 quadruple times, if we multiply 8 by 4 the result is 32, so, the second digit is 4 and the remainder is 6, which is the difference between 38 and 32. Since the weighted value of 80 is 1, therefore the last digit is 6. ``` 294 256 64 x 4 38 32 8 x 4 6 1 x 6 0 ``` Multipliers of the process are equivalent to the octal number when read from top to bottom. This method is also called the repeated subtraction method and is quite easy if we convert decimal to binary since the value corresponds to a particular bit either it fits (1) or not (0). Let's consider the example below. Convert 23810 to binary. | Base and Exponent | Weight | Binary number | |---|---|---| | 28 | 256 | 1 | | 27 | 128 | 1 | | 26 | 64 | 1 | | 25 | 32 | 0 | | 24 | 16 | 1 | | 23 | 8 | 1 | | 22 | 4 | 1 | | 21 | 2 | 0 | | 20 | 1 | 0 | Following the same method we did a while ago, the largest bit value in this conversion is 128 weight. Therefore, ``` 238 128 128 x 1 110 64 64 x 1 46 32 32 x 1 14 16 x 0 14 8 x 1 6 4 x 1 2 2 x 1 0 ``` Multipliers of the process are equivalent to the binary number when read from top to bottom, we just add trailing 0 to complete the base-exponent used. As you can observe, we multiply 16 (24) by 0 since the remaining number, which is 14, is less than 16. Also, we assigned 0 to the least significant bit since the remaining number is already 0. This method is quite cumbersome and requires familiarity with the powers of the base being used. Another method is used to convert decimal to base-n which is faster and easier than the repeated subtraction method. The division-remainder method employs the idea of successive subtractions by powers of the base. The remainders that we get when we sequentially divided by the base end up being the digits of the result, which are read from bottom to top. Let us convert 53210 to base-5 using division-remainder method. ``` 5 532 2 5 106 1 5 21 1 5 4 4 5 0 0 ``` Reading the remainders from bottom to top, we have 53210 = 41125. Let us try to convert 2410 to base-16 using division-remainder method. ``` 16 241 1 16 15 15 0 ``` Reading the remainders from bottom to top, we have 24110 = F116. **NOTE: 15 is equivalent to F in hexadecimal** This method works with any base, and because of the simplicity of calculations, it is particularly useful in converting decimal to binary. The methods we discuss can be used to directly convert any number in any base to any other base, say from base-5 to base-8. However, in most cases, it is faster and more accurate to convert to base-10 and then to the desired base. For example, let us convert 3415 to base-8. First, convert 3415 to decimal using weighted numbering system. 341 = (3 x 52) + (4 x 51) + (1 x 50) = 9610 Then, convert 9610 to base-8 using division-remainder method. ``` 8 96 0 8 12 4 8 1 1 0 ``` Reading the remainders from bottom to top, we have 9610 = 1408. Therefore, 3415 is equivalent to 1408. Let us try convert 101101012 to base-16 and base-8. First, convert 101101012 to decimal using weighted numbering system. 10110101 = (1 x 27) + (0 x 26) + (1 x 25) + (1 x 24) + (0 x 23) + (1 x 22) + (0 x 21) + (1 x 20) = 18110 Then, convert 18110 to hexadecimal and octal. ``` 16 181 5 16 11 11 0 8 181 5 8 22 6 8 22 0 ``` Therefore, 101101012 = B516 = 2658. There's an easy way to convert bases that are power of two, like base-2, base-4, base-8, base-16, etc. Note that 16 = 2<sup>4</sup>, a group of 4-bits (called hextet) is easily recognized as hexadecimal and 8 = 2<sup>3</sup>, a group of 3-bits (called an octet) is known as one octal digit. Using this idea, we can easily convert binary numbers to hexadecimal or octal by grouping the bits. Using the same example, let us convert 101101012 to hexadecimal and octal. ``` 1011 0101 11 5 101101012 = B516 010 110 101 2 6 5 101101012 = 2658 ``` In case that the most significant bits (leftmost bits) have fewer bits than of required, zeroes can be added. ### APPLICATION Exercise #1. Tom is trapped on the top floor of a department store. It's just before Christmas and he wants to get home with his presents. What can he do? He has tried calling, even yelling, but there is no one around. Across the street he can see some computer person still working away late into the night. How could he attract her attention? Tom looks around to see what he could use. Then he has a brilliant idea-he can use the Christmas tree lights to send her a message! He finds all the lights and plugs them in so he can turn them on and off. He uses a simple binary code, which he knows the woman across the street is sure to understand. Can you work it out? **[Image of a Christmas tree with lights. There are some more details: a man on the top floor of a building and a woman across the street. There is a list of letters, with numbers above it. There are empty spaces between the lights to fill with a letter. This is the first letter of the alphabet. The letters n to z also have numbers. They are 14 to 26.]** Exercise #2. Determine which among the number bases are valid and not. Write YEY if it is a valid number base otherwise write YAY. | Number | YEY or YAY? | |---|---| | 1. 7188 | YAY | | 2. 101103 | YEY | | 3. OA1210 | YEY | | 4. F0614 | YEY | | 5. 6547 | YEY | | 6. 7808 | YEY | | 7. 31755 | YAY | | 8. A3113 | YEY | | 9. 1101102 | YEY | | 10. 12314 | YAY | Exercise #3. Based on your answers on exercise 2, convert the following numbers to the required base. Show your solution (you may use any method). | Number | Decimal | Base-5 | Base-8 | Base-16 | |---|---|---|---|---| | 1. | | | | | | 2. | | | | | | 3. | | | | | | 4. | | | | | | 5. | | | | | ### KEEP IT UP! You've just finished lesson 1 of this module. If you have clarifications of this lesson, please ask your instructor during the synchronous class time. In order to know more about how data are represented in the computer system especially floating-point and signed numbers, please proceed to the next lesson of this module, which will discuss signed integer and floating-point representation.