OCR A-Level Computer Science H446
Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation
Software Development
Types of Programming Language
Exchanging Data
Networks
Web Technologies
Data Types and Number Representation
Data Structures
Boolean Algebra
Legal, Moral, Cultural and Ethical Issues
Elements of Computational Thinking
Problem Solving and Programming
Algorithms
Data Types and Number Representation
Floating point addition and subtraction, and fixed point compared
- 3 things to know
- Component 01
Overview
Recall questions on aligning exponents and adding or subtracting floating point numbers, arithmetic shifts of the mantissa, normalising results, rounding and associativity, fixed point numbers and their range, and choosing between fixed and floating point.
What you need to know
Answer each one before you reveal it.
An eight-bit fixed point number has four bits before the point and four after. What is the value of 01101010?
Give two practical advantages of fixed point over floating point.
Questions from this subtopic
Each one with the model answer underneath.
- 1
What is the first thing you must do before adding two floating point numbers, and why?
Model answer
Make the two exponents the same. The mantissas are only meaningful relative to their own exponents, so adding them while the exponents differ would be adding digits of different place values, like adding hundreds to units. Once both numbers are scaled by the same power of two, the mantissas line up and can be added directly.
- 2
When you align the exponents, which number do you adjust, and in which direction?
Model answer
Adjust the number with the smaller exponent, raising its exponent to match the larger one and shifting its mantissa right by the same number of places. You shift the smaller number rather than the larger because bits shifted off the right-hand end of a small number are the least significant, so the loss is minimal, whereas shifting the larger number left would push its most significant bits out of the mantissa and destroy the answer.
- 3
Add the floating point numbers 01010000 0011 and 01100000 0001, using an eight-bit two's complement mantissa and a four-bit two's complement exponent.
Model answer
The answer is 01101000 0011. The first number is 0.625 x 8 = 5.0 and the second is 0.75 x 2 = 1.5. Align by raising the second exponent from 1 to 3, shifting its mantissa right two places to give 00011000. Now add the mantissas: 01010000 + 00011000 = 01101000. The exponent stays at 0011. The result is 0.8125 x 8 = 6.5, and 5.0 + 1.5 = 6.5. The first two bits of the answer differ, so it is already normalised.
- 4
When you shift a mantissa right to align exponents, what do you shift in on the left?
Model answer
A copy of the sign bit, which means zeros for a positive mantissa and ones for a negative one. This is an arithmetic right shift, and it is essential because the sign bit carries a place value of minus 1. Shifting in zeros on a negative mantissa would clear the sign and turn the number positive.
- 5
Add 01100000 0010 and 11010000 0001 in the same format, and show the alignment step carefully.
Model answer
The answer is 01001000 0010. The first number is 0.75 x 4 = 3.0 and the second is minus 0.375 x 2 = minus 0.75. Align by raising the second exponent from 1 to 2, shifting its mantissa right one place with sign extension, so 11010000 becomes 11101000, which is minus 0.1875 and, times 4, still minus 0.75. Adding the mantissas, 01100000 + 11101000 = 01001000 with a carry out that is discarded. The exponent is 0010, and 0.5625 x 4 = 2.25, which matches 3.0 minus 0.75.
- 6
In the sum above, what would have gone wrong if the mantissa 11010000 had been shifted right with zeros in?
Model answer
It would have become 01101000, which is plus 0.8125 instead of minus 0.1875. The number would have flipped from minus 0.75 to plus 3.25, so the answer would have come out as 6.25 rather than 2.25. Forgetting to extend the sign bit on a right shift is the single commonest mistake in floating point arithmetic, and it produces an answer that is wrong in sign as well as size.
Other ways to work this
The same content, four other ways.
What is inside Levo
Six ways to work the same material.
Every question in Data Types and Number Representation, on a schedule.
Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.
Or £46 a year, about £3.83 a month. Cancel anytime.