320 likes | 534 Views
Chapter 1.7 Storing Fractions. Excess Notation, continued….
E N D
Excess Notation, continued… • In this notation, "m" indicates the total number of bits. For us (working with 8 bits), it would be excess 2^7. To represent a number (positive or negative) in excess 2^7, begin by taking the number in regular binary representation. Then add 2^7 (=128) to that number. For example, 7 would be 128 + 7=135, or 2^7+2^2+2^1+2^0, and, in binary,10000111. We would represent -7 as 128-7=121, and, in binary, 01111001. • Note: • Unless you know which representation has been used, you cannot figure out the value of a number. • A number in excess 2^(m-1) is the same as that number in two's complement with the leftmost bit flipped. http://www.math.grin.edu/~rebelsky/Courses/152/97F/Readings/student-binary.html#excess
Chapter 1.7 Storing Fractions
Chapter 1.7 Storing Fractions • In contrast to the storage of integers, the storage of a value with a fractional part requires that we store not only the pattern of 0s and 1s representing its binary representation, but also the position of the radix point. • A popular way of doing this is based on scientific notation and is called floating-point notation.
Floating-Point Notation • Let us explain floating-point notation with an example using only one byte of storage. • Although machines normally use much longer patterns, this eight-bit format is representative of actual systems and serves to demonstrate the important concepts without the clutter of long bit patterns.
Floating-Point Notation • We first designate the high-order bit of the byte as the sign bit. • 0 – nonnegative • 1 – negative
Floating-Point Notation • Next, we divide the remaining seven bits of the byte into two groups, or fields • Exponent field • Mantissa field
Floating-Point Notation • Let us designate the three bits following the sign bit as the exponent field and the remaining four bits as the mantissa field.
Floating-Point Notation • We can explain the meaning of the fields by considering the following example: • Suppose a byte contains the bit pattern 01101011
Floating-Point Notation • Analyzing this pattern with the preceding format, we see that the sign bit is 0, the exponent is 110, and the mantissa is 1011.
Floating-Point Notation • To decode the byte, we first extract the mantissa and place a radix point on its left side, obtaining • .1011
Floating-Point Notation • Next, we extract the contents of the exponent field and interpret it as an integer stored using the three-bit excess method.
Floating-Point Notation • Thus the pattern in the exponent field in our example represents a positive 2 • 110 -> 2 excess notation. • Remember what the others are? • 100 -> 0 • etc
Floating-Point Notation • The exponent field is +2 • This tells us to move the radix in our solution to the RIGHT by two bits. • A positive exponent means to move the radix to the right • A negative exponent means to move the radix to the left
Floating-Point Notation • So we have: • .1011 • 10.11 • What is it represent in decimal? • 2 ¾ • Remember fractions in binary?
Floating-Point Notation • Review of fractions in binary:
Floating-Point Notation • 10.11 • The part at the left to the radix point is • 10 • The part at the right to the radix point is • 11 • 10 -> 2 • 11 -> 1* ½ + 1* ¼ -> ¾ • So the number altogether is 2 ¾
Floating-Point Notation • Don’t forget the SIGN BIT • In this example, it is 01101011 • So, the sign bit is 0 • It is nonnegative • So, we can conclude that the byte 01101011 represents 2 ¾
Floating-Point Notation • 1 byte -> 8 bits • This need to be memorized
Floating-Point Notation • Let’s do another example • 10111100 • First of all, we extract it • Sign bit 1 • Exponent 011 • Mantissa 1100
Floating-Point Notation • Mantissa .1100 • Exponent 011 • which means -1 • move the radix to the left • .01100 • which represent 3/8 • SIGN BIT 1 • which means negative
Floating-Point Notation • The pattern 10111100 represents – 3/8 • Some more examples
Floating-Point Notation • To store a value using floating point notation. • We reverse the process. • For example, to encode 1(1/8)
Floating-Point Notation • First we express it in binary notation and obtain: 1.001 • Because it is positive, so the sign bit is 0 • Now we can copy the bit pattern into the mantissa field from left to right, starting with the left most 1 in the binary representation. • _ _ _ _ 1001
Floating-Point Notation • _ _ _ _ 1001 • Also we have the sign bit is 0 since it’s positive number, so we have • 0 _ _ _ 1001 • Since it is 1.001, .1001->1.001, the radix point moves to the right one bit. So, we need the 1 at the exponent field • Which is 101
Floating-Point Notation • So, we filled out all the fields at this point • Number 1 1/8 is • 01011001
Floating-Point Notation • Note, there is a subtle point you may have missed when filling in the mantissa field. The rule is to copy the bit pattern appearing in the binary representation from left to right, STARTING WITH THE LEFTMOST 1 • Example, 3/8 is .011 in binary, in mantissa it will be 1100 • Instead of 0110
Floating-Point Notation • This is because we fill in the mantissa field starting with the leftmost 1 that appears in the binary representation. • This rule eliminates the possibility of multiple representations for the same value. • This representation is said to be in normalized form.
Floating-Point Notation • If we don’t normalize them, for the same number, there can be more than one representation. • For example: 3/8 • It can be 000111100 • Or 000000110 • Etc.
Floating-Point Notation • Truncation Error or Round-off Error
Homework #6 • Page 60 • Question 1 a,e • 2 b,e • 3 • Due next Thursday. • Remember to write your name and student ID on your homework.