LCSC > Natural Science and Mathematics > Computer Science > Patterson-McNeill > Foundations > Notes


CS111
Notes
Spring 2009
  1. Number Systems
  2. Orders of Magnitude
  3. Integers
  4. Floating Point
  5. ASCII

Floating Point

Overflow occurs when the value that we compute cannot fit into the number of bits we have allocated for the result.

In computing we call all noninteger values real values. That is, a real number has a whole number part and a fractional part, either of which may be zero.

First, we need to look at binary fractions.

Binary Fractions

We use a radix point in the same role as the decimal point in decimal notation. That is, the digits to the left of the radix point represent the integer part of the value. The digits to the right represent the fractional part of the value.

_  _  _ . _  _  _
22 21 20  2-1 2-2 2-3

2-1 = 1/2
2-2 = 1/4
2-3 = 1/8
Therefore, 101.101 is 5 5/8 and 101.01011 is 5 11/32

Floating Point Representation

How is this number represented in a computer? We store the number in a notation similar to scientific notation and include information showing where the radix point is, and what the sign is. Any real value can be described by three properties:

  1. the sign
  2. the mantissa (the digits with the radix to the left)
  3. the exponent

This is floating point notation.

Let's look at some decimal numbers first, to get a feel for what needs to be done. First we need to know how many digits in the mantissa. Let's choose 5. We can convert our real numbers into a 5 digit mantissa with exponent. Floating point notation puts the radix point in front of the mantissa so we will look at that form as well.

Real 5 digits and an exponent Floating point
12001.00 12001 * 100 +.12001 * 105
-120.01 -12001 * 10-2 -.12001 * 103
0.12 12000 * 10-5 +.12000 * 100
-1231000 12310 * 102 -.12310 * 107
0.01231 12310 * 10-6 +.12310 * 10-1
15,555,555 15555 * 103 +.15555 * 108

The last example shows us one of the problems with floating-point notation – truncation error. Part of the value being stored is lost because the mantissa field is not large enough.

If the mantissa held only 5 digits then the last (least significant) digits are lost.

Note that we need to have positive and negative values for the exponent. And that the mantissa always starts with a non-zero digit.

Now let's switch to binary. Although a common standard uses 64 bits for a floating-point number: 1 bit for the sign, 11 bits for the exponent, and 52 bits for the mantissa, we will use an abbreviated version. Let's use one byte: 1 bit for the sign, 3 bits for the exponent, and 4 bits for the mantissa.

.
|---- -----
| |     |
| |     mantissa
| exponent
sign

The sign is easy enough 0 or 1.

The exponent has 3 bits and must be either + or -. We could use 2's complement, but excess notation is used instead! 3 bits means excess 4 notation. That leaves 4 bits for the mantissa. Why excess notation? It gives the best range of exponents and ease of wiring the circuitry.

Review:
000  0 – 4 = -4
001  1 – 4 = -3
010  2 – 4 = -2
011  3 – 4 = -1
100  4 – 4 = 0
101  5 – 4 = 1
110  6 – 4 = 2
111  7 – 4 = 3

Rules:

  1. Determine the sign bit
  2. Convert the whole number to binary
  3. Convert the fraction to binary
  4. Move the radix to the left of the most significant digit (left-most non-zero digit)
  5. Determine the exponent in excess 4 notation

Examples:

  1. +2 3/4
    1. This is positive so our sign bit is 0
    2. 2 is 10
    3. 3/4 is .11
    4. This gives us 10.11
      Move the radix two places to the left: .1011
    5. So the exponent is +2: 110 in excess 4
    6. Giving us: 0 110 1011
  2. -1.1875
    1. This is negative so our sign bit is 1
    2. 1 is 1
    3. .1875 is 3/16 giving us .0011
    4. This gives us 1.0011: Because we have 4 bits we have to use 1.001: Move the radix one place to the left: .1001
    5. So the exponent is +1: 101 in excess 4
    6. Giving us: 1 101 1001
  3. +0.34375
    1. This is positive so our sign bit is 0
    2. There is no whole number part
    3. .34375 is 11/32 giving us .01011: We need four significant digits. The leading zero is not significant.
    4. This gives us 0.1011. Move the radix point one place to the right: .1011
    5. So the exponent is -1: 011 in excess 4
    6. Giving us: 0 011 1011
  4. What is 10111100 in decimal?
    1. Split it apart into its pieces: 1 011 1100
    2. The sign is 1 or negative
    3. The exponent is 011 or -1
    4. The mantissa is 1100. Move the radix one place to the left: .01100 giving us 3/8
    5. Our number is -3/8
  5. What is 01011010?
    1. Split it apart into its pieces: 0 101 1010
    2. The sign is 0 or positive
    3. The exponent is 101 or +1
    4. The mantissa is 1010. Move the radix one place to the right: 1.010 giving us 1 1/4

    5. Our number is +1 1/4

Syllabus Notes
Revised - 8 January 2009