Web www.ib-computing.com

## Floating point representation

4.1.3
Both fixed (previous) and floating point representations are required.

The number part is usually normalized , ie made to fit within a certain range (in the above examples, the first digit after the decimal point has to be 1 through 9).

More bits would be allocated in a real computer system.

Which is the topic of the next page .

On this page: [ mantissa & exponent | range of numbers | compared to integers ]

Mantissa and Exponent

First some terminology:

given 0.32855932 x 10 4 .

The number (ie 0.32855932) is called the mantissa and the power (ie 4) is called the exponent .

To represent binary floating-point numbers we will use a binary (fractional) mantissa and an integer exponent which both use two's complement representation in 16-bits.

A possible compromise between a large mantissa (greater accuracy) and a large exponent (greater range) could be to allocate 10 bits for the mantissa and 6 for the exponent:

<--------------------------------- mantissa -----------------------------><------------exponent -------->

 -1 1/2 1/4 1/8 1/16 1/32 1/64 1/128 1/256 1/512 -32 16 8 4 2 1

^
There is an implied point after the MSB.

 -1 1/2 1/4 1/8 1/16 1/32 1/64 1/128 1/256 1/512 -32 16 8 4 2 1 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 0

What is this in decimal?

Well, do it in two parts, first the mantissa stays as it is; the value of the exponent is +4.

Therefore the binary point must be moved four places to the right in the mantissa:

0.110101000 becomes 1101.01000 that is 13.25 in decimal.

Now for a negative mantissa and exponent:

 -1 1/2 1/4 1/8 1/16 1/32 1/64 1/128 1/256 1/512 -32 16 8 4 2 1 1 1 0 1 1 0 1 0 0 0 1 1 1 0 1 0

Stage 1 - complement the mantissa:

1.101101000 becomes 0.0 1 0 0 1 1 0 0 0, that is - 0.010011000 in "ordinary" binary.

Stage 2 - shift the mantissa, the exponent is -6, so move the binary point 6 places to the left:

- 0.010011000 becomes - 0.000000010011000

or something quite small 1/256 + 1/2048 + 1/4096 = (16+2+1)/4096 = 0.00415039 -ish.

Convert the following to decimal equivalents:

 -1 1/2 1/4 1/8 1/16 1/32 1/64 1/128 1/256 1/512 -32 16 8 4 2 1 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

In the second and third representations above, there are leading zeros following the binary point and therefore less space to store any low value bits.

Notice that the first number 2 1/128 could not be stored with the higher exponents, the LSB of the mantissa would be lost. In order to preserve the maximum possible accuracy , the numbers are normalised (as for the decimal floating point number example given at the start of this section).

Because we are using two's complement binary fractions , normalising positive and negative numbers is different. Positive is not so bad: the MSB (excluding the sign bit) must be a 1 (ie no trailing zeros after the point).

Thus

0.000111100 would be expressed as 0.111100000

With a corresponding shift in the exponent:

0.000111100 000000 then becomes 0.111100000 111101

an exponent of -3.

For negative numbers there must be no leading 1's to the left of the point, the MSB must be a zero (which is the significant bit in two's complement):

1111100100 would be expressed as 1.001000000

(Why? Leading 1's in a two's complement negative number may be ignored in just the same way that leading zeros may be ignored in a positive number).

This requires a shift of 5 places as shown below:

1111100100 000000 then becomes 1.001000000 000101

To confirm this, complement the mantissa and then shift it 5 places to the right.

Quick Quiz:

Which of the following decimal numbers link with which normalised binary numbers:

 123 0110000000111110 0.1875 1000100000111111 -15/32 1011000100000110 -39.5 0111101100000111

Question : What happens if you allocate 5 bits to the mantissa and 8 bits to the exponent?

Range of Normalised Floating Point Binary Numbers

Consider a representation using only 10 bits, 6 for the mantissa and 4 for the exponent: the principal is the same but the numbers are easier to handle mentally.

 -1 1/2 1/4 1/8 1/16 1/32 -8 4 2 1

What is the largest positive number that can be represented? The largest positive number will require the largest positive mantissa and the largest positive exponent.

What is the smallest positive number that can be represented?

What is the largest negative number that can be represented?

What is the smallest negative number that can be represented?

Integer and Floating Point Representations Compared
The advantages of integer representation are:

Complete accuracy of storage (as long as there are enough bits allocated).
Large range is possible with enough bits.
Overflow is easily recognised and trapped by programmers.
The advantages of floating point representation are:

A larger range of numbers can be stored.
Fractional numbers can be stored.
Floating point errors can also accumulate especially in long and complicated calculations leading to a loss of precision in output.

related: [ Topic 4 home | previous: fixed point binary | next: errors ]

 The site is partly financed by advertising revenue, partly by online teaching activities and partly by donations. If you or your organisation feel these resouces have been useful to you, please consider a donation, \$9.95 is suggested. Please report any issues with the site, such as broken links, via the feedback page, thanks.