levo

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.

Your recallNot started
Key term

What is the first thing you must do before adding two floating point numbers, and why?

Key term

An eight-bit fixed point number has four bits before the point and four after. What is the value of 01101010?

Evaluation

Give two practical advantages of fixed point over floating point.

Questions from this subtopic

Each one with the model answer underneath.

  1. 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. 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. 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. 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. 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. 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.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

A0 + 0 gives 0.
B0 + 1 gives 1.
C1 + 1 gives 0 carry 1.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

A global variable means a variable reachable from anywhere in the program.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

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.