Floating point numbers introduction
Floating-point numbers
So far, and staying with our byte, we know that in two's complement form, we can represent integers (whole numbers) from +127 to -128. We can't represent real numbers using this system. We can represent real numbers using fixed-point representation but it is only useful if the data is predictable and within a certain range. What we need is to be able to represent a wide range of real numbers. Switching to decimal for a moment, you can represent these real decimal numbers in a different way. Look at these examples.
-
- 325.5 can be represented as 0.3255 x 103
- 1050.23 can be represented as 0.1050 x 104
- 478934.52 can be represented as 0.47893452 x 106
- 0.005 can be represented as 0.5 x 10-2
- 0.000421 can be represent as 0.421 x 10-3
So you can have a number like 5000.23 and represent it as 0.500023 x 104. The way of representing numbers in different forms involves moving (or ‘floating’) the decimal point to a new position. The number part e.g. 0.500023 in the above example is called the ‘mantissa’. The number above the 10, the 4 in this case, is called the ‘exponent’.
-
- The mantissa shows you what actual digits are in the number.
- The exponent shows you how many places to move the decimal point and in what direction, so that you get back the original number.
So, to represent a real number in this form, you need to know 2 numbers - the mantissa and the exponent. Note that all these numbers are positive. With positive numbers, we always get the mantissa so that it lies between zero and one. In fact, you can represent a number in all sorts of ways. For example, 3000 could be represented as
0.03 x 105, or 0.3 x 104, or 3 x 103 and so on. For reasons that will be explained later, always get the mantissa of denary positive numbers to lie between 0 and 1.
Remember - the mantissa of positive binary numbers should always begin with '01'.
In the following examples, we are not using two's complement (yet). Study the following:
-
- 1001 can be represented as 0.1001 x 24 ----- This is the same as 0.1001 x 2100
- 101111 can be represented as 0.101111 x 26 ----- This is the same as is 0.101111 x 2110
- 1101111 can be represented as 0.1101111 x 27 ----- This is the same as is 0.1101111 x 2111
- 0.00111 can be represented as 0.111 x 2-2 ----- This is the same as is 0.111 x 2-10
- 0.00001 can be represented as 0.1 x 2-4 ----- This is the same as is 0.1 x 2-100
- 0.000111 can be represented as 0.111 x 2-3 ----- This is the same as is 0.111 x 2-11
Note that all these numbers are positive. With positive numbers, we always get the mantissa to start in the form "01" although there are an infinite number of ways we could represent each number, as we saw with the decimal example: 3000 could be represented as 0.03 x 105, or 0.3 x 104, or 3 x 103 and so on. Interestingly, when we look at negative real numbers, we always get them to begin with "10". When we get a number into one of these forms (01 or 10), we say that the number is in its normalised form.