Download Data Representation - Assembler Programming and Computer Organization - Lecture Slides and more Slides Computer Architecture and Organization in PDF only on Docsity!
Chapter 2 Data Representation
- Chapter 2: Data Representation – 1
CS140 Computer Organization
Chapter 2 Objectives
- Understand the fundamentals of numerical data representation
and manipulation in digital computers – both integer and floating point.
- Master the skill of converting between various radix systems.
- Understand how errors can occur in computations because of
overflow and truncation.
- Gain familiarity with the most popular character codes.
- Understand the concepts of error detecting and correcting
codes.
- Chapter 2: Data Representation (^) Docsity.com– 2
2.2 Positional Numbering Systems
- Bytes store numbers using the position of each bit to represent a power of 2. - The binary system is also called the base-2 system. - Our decimal system is the base-10 system. It uses powers of 10 for each position in a number. - Any integer quantity can be represented exactly using any base (or radix ).
- The decimal number 947 in powers of 10 is:
- The decimal number 5836.47 in powers of 10 is:
- Chapter 2: Data Representation – 4
9 10 2 + 4 10 1 + 7 10 0
5 10 3 + 8 10 2 + 3 10 1 + 6 10 0
2.2 Positional Numbering Systems
- Binary works the same as decimal
- The binary number 11001 in powers of 2 is:
- When the radix of a number is something other than 10, the base is denoted by a subscript. - Sometimes, the subscript 10 is added for emphasis: 110012 = 25 10 - Chapter 2: Data Representation – 5
2.3 Decimal to Binary Conversions
- Converting 190 to base 3...
- The next power of 3 is 3 (^3) = 27. We’ll need one of these, so we subtract 27 and write down the numeral 1 in our result.
- The next power of 3, 3 2 = 9, is too large, but we have to assign a placeholder of zero and carry down the 1. - Chapter 2: Data Representation – 7
Subtraction Method
2.3 Decimal to Binary Conversions
- Converting 190 to base 3...
- 3 1 = 3 is again too large, so we assign a zero placeholder.
- The last power of 3, 3 0 = 1, is our last choice, and it gives us a difference of zero.
- Our result, reading from top to bottom is: 19010 = 21001 3 - Chapter 2: Data Representation – 8
Subtraction Method
2.3 Decimal to Binary Conversions
- This shows the subtraction method to convert the decimal 0.8125 to binary. - Our result, reading from top to bottom is: 0.8125 10 = 0.1101 2 - This method works with any base, not just binary. - Chapter 2: Data Representation – 10
Subtraction Method
Note: The book also talks about the Multiplication Method which you may prefer.
2.3 Decimal to Binary Conversions
- The binary numbering system is the most important radix system for digital computers.
- But, it’s difficult to read long strings of binary numbers-- and even a modest decimal number becomes a very long binary number. - For example: 110101000110112 = 13595 10
- For compactness and ease of reading, binary values are usually expressed using the hexadecimal, or base-16, numbering system. - Chapter 2: Data Representation – 11
- The hexadecimal numbering system uses the numerals 0 through 9 and the letters A through F. - The decimal number 12 is C 16. - The decimal number 26 is 1A 16.
- It is easy to convert between base 16 and base 2, because 16 = 2^4.
- Thus, to convert from binary to hexadecimal, all we need to do is group the binary digits into groups of four.
HEX
A group of four binary digits is called a hextet Docsity.com
2.4 Signed Integer Representation
- To represent negative values, computer systems allocate the high-order bit to indicate the sign of a value. - The high-order bit is the leftmost bit in a byte. It’s also called the most significant bit.
- The remaining bits contain the value of the number.
- There are three ways in which signed binary numbers may
be expressed:
- Signed magnitude,
- One’s complement we won’t do much with this here
- Two’s complement.
- Chapter 2: Data Representation (^) Docsity.com– 13
2.4 Signed Integer Representation
- In an 8-bit word, signed magnitude representation places the absolute value of the number in the 7 bits to the right of the sign bit. - Chapter 2: Data Representation – 14
In 8-bit signed magnitude,
- Positive 3 is: 00000011
- Negative 3 is: 10000011
- Computers perform arithmetic operations on signed magnitude numbers the same way as humans do pencil and paper arithmetic. - Humans ignore the signs of the operands while doing a calculation, applying the appropriate sign at the end.
2.4 Signed Integer Representation
- Example:
- Using signed magnitude binary arithmetic, find the sum of 75 and 46.
- Convert 75 and 46 to binary, and arrange as a sum. Separate the (positive) sign bits from the magnitude bits. - Chapter 2: Data Representation – 16
- As in decimal arithmetic, find the sum starting with the rightmost bit and work left.
- In the second bit, we have a carry, so we note it above the third bit.
2.4 Signed Integer Representation
- Example:
- Using signed magnitude binary arithmetic, find the sum of 75 and 46.
- The third and fourth bits also give us carries.
- Once we have worked our way through all eight bits, we are done. - Chapter 2: Data Representation – 17
In this example, we were careful to pick two values whose sum would fit into seven bits. If that’s not the case, we have a problem.
Example:
Using signed magnitude binary arithmetic, find the sum of 107 and 46.
- The carry from the seventh bit overflows and is discarded, giving us the erroneous result: 107 + 46 = 25.
2.4 Signed Integer Representation
- Signed magnitude representation is easy for people to understand, but needs complicated computer hardware.
- Another disadvantage: it allows two different representations for zero: positive zero and negative zero.
- So computers systems employ complement systems for numeric value representation. - Chapter 2: Data Representation – 19
4-bit Binary Decimal 1000 - 1001 - 1010 - 1011 - 1100 - 1101 - 1110 - 1111 - 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7
2.4 Signed Integer Representation
- To express a value in two’s complement:
- If the number is positive, just convert it to binary and you’re done.
- If the number is negative, find the one’s complement (change each of the bits) of the number and then add 1.
- Example: