Data Types T4 Floating Point Arithmetic
Data Types T4 Floating Point Arithmetic
OCR arithmetic
A Level Unit 6
Data types
Computer
Science
H446 – Paper 1
4
Objectives
• Represent positive and negative numbers with a
fractional part in floating point form
• Normalise un-normalised floating point numbers with
positive or negative mantissas
• Add and subtract floating point numbers
Floating point arithmetic
Unit 6 Data Types
Fixed point
• Fixed point binary numbers have a pre-determined
number of bits before and after the point
• This makes fixed point numbers easier to process
but they cannot represent the range or accuracy of
numbers that may be required
Floating point arithmetic
Unit 6 Data Types
Sign
bit Mantissa Exponent
0 1 0 1 1 0 1 0 0 0 1 1
• The number above represents the number
0.1011010 x 23 since the exponent is 3 in
decimal
101.1010
• This is 101.1010 or 4 + 1 +0.5 + 0.125
Floating point arithmetic
Unit 6 Data Types
• Answer 13.5
Floating point arithmetic
Unit 6 Data Types
Negative mantissa
• Try this one:
1 . 0101011 0101
• Find the two’s complement of the mantissa (0.1010101)
• Translate the exponent to decimal giving 5
• Move the binary point 5 places right
• Do you get an answer of -21.25?
Floating point arithmetic
Unit 6 Data Types
Negative mantissa
• Try this one:
1 . 0101011 0101
• Find the two’s complement of the mantissa (0.1010101)
• Translate the exponent to decimal giving 5
• Move the binary point 5 places right 10101.01
• Do you get an answer of -21.25?
Floating point arithmetic
Unit 6 Data Types
Negative exponent
• The leftmost bit of the exponent is a sign bit, just as
it is in the mantissa
• An exponent of 1000 in a 4-bit exponent is -8
• You can calculate the denary value of a negative
exponent, for example 1011, as -8 + 3 = -5
• Or, you can use the twos complement method which
will give you the same result
• What is the denary value of negative exponent 1111?
Floating point arithmetic
Unit 6 Data Types
Negative exponent
• If the exponent is negative, the binary point must be
moved left instead of right
e.g. convert 0.1100000 1110 to denary,
assuming an 8-bit mantissa and 4 bit exponent
• Write down the mantissa, 0.1100000
• Translate the exponent from binary to decimal; 1110 = -2
• The mantissa has to be moved 2 places left to divide it by 22
• Binary number is 0.0011000 = 0.125 + 0.0625 = 0.1875
Floating point arithmetic
Unit 6 Data Types
Worksheet 4
• Now try the questions in Task 1 of the worksheet
Floating point arithmetic
Unit 6 Data Types
Normalisation
• Normalisation is the process of moving the binary
point of a floating point number to provide the
maximum level of precision for a given number of
bits
• This is achieved by ensuring that the first digit after
the binary point is a significant digit
Floating point arithmetic
Unit 6 Data Types
Normalisation
• Here are some examples in denary:
0.1234567 x 107 = 1,234,567
0.0123456 x 108 = 1,234,560
0.0012345 x 109 = 1,234,500
• The first representation with a significant (non-zero)
digit after the decimal point has the maximum
precision using the same number of digits
Floating point arithmetic
Unit 6 Data Types
Normalisation
• In normalised floating point form:
A positive number has a sign bit of 0
and the next digit is always 1
• This means that the mantissa of a positive number
in normalised form always lies between ½ and 1
Floating point arithmetic
Unit 6 Data Types
Example
• Normalise the binary number 0.0011010 0100
• The binary point needs to move 2 places to the right so that
there is a 1 following the binary point
• Pad with 0s at the righthand end, giving 0.1101000
• To compensate for making the mantissa larger, we must
make the exponent smaller
• Subtract 2 from the exponent making it 0010
• The normalised number is 0.1101000 0010
Answer to example
• Normalising the number 0.0000111 0111
means moving the binary point 4 places right, and
subtracting 4 from the exponent
• This gives 0.1110000 0011
Floating point arithmetic
Unit 6 Data Types
Answer to exercise
• Convert 17.25 to normalised floating point binary
• Convert to fixed point binary 10001.010
• Move binary point 5 places left
• Set exponent to 5
Worksheet 4
• Now try Task 2 on the worksheet
Floating point arithmetic
Unit 6 Data Types
Example
• Add the two floating point numbers
A = 0.1100000 0001 B = 0.1111100 0011
• Convert to fixed point and add:
A = 1.1000
B = 111.1100
Sum = 1001.0100
• The number is positive, so sign bit will be 0
• Convert to normalised floating point:
Result = 0.1001010 0100
Floating point arithmetic
Unit 6 Data Types
Example
• Subtract the two floating point numbers, A - B
A = 0.1101000 0100 B = 0.1110000 0011
• Convert to fixed point:
A = 1101.0000
B = - 0111.0000 (one’s complement =
1000.1111)
Worksheet 4
• Now try Task 3 on the worksheet
Floating point arithmetic
Unit 6 Data Types
Plenary
• Be sure you can:
• Convert floating binary numbers to decimal and vice versa
• Normalise floating-point numbers with positive and negative
mantissas
• Explain the effect of increasing the size of the mantissa and
exponent
• Add and subtract floating point numbers
Floating point arithmetic
Unit 6 Data Types
Copyright
This unit and all the worksheets, PowerPoint presentations, teaching guides and other associated files
distributed with it are supplied to you by PG Online Limited under licence and may be used and copied by you
only in accordance with the terms of the licence. Except as expressly permitted by the licence, no part of the
materials distributed with this unit may be used, reproduced, stored in a retrieval system, or transmitted, in any
form or by any means, electronic or otherwise, without the prior written permission of PG Online Limited.
Licence agreement
This is a legal agreement between you, the end user, and PG Online Limited. This unit and all the worksheets,
PowerPoint presentations, teaching guides and other associated files distributed with it is licensed, not sold, to
you by PG Online Limited for use under the terms of the licence.
The materials distributed with this unit may be freely copied and used by members of a single institution on a
single site only. You are not permitted to share in any way any of the materials or part of the materials with any
third party, including users on another site or individuals who are members of a separate institution. You
acknowledge that the materials must remain with you, the licencing institution, and no part of the materials may
be transferred to another institution. You also agree not to procure, authorise, encourage, facilitate or enable any
third party to reproduce these materials in whole or in part without the prior permission of PG Online Limited.