teach-ict.com logo

THE education site for computer science and ICT

3. Subtracting floating point

Subtraction is very similar to the addition process, but the second number needs to be made into its negative in two's compliment.

For example to carry out the subtraction 3 - 2, this is done with 3 + (twos compliment of 2)

Subtract these two floating point numbers that have mantissa and exponent parts

             0.1000      001
             0.0111      011 -

The first thing to do is to use the exponent to place the binary point. The first number is exponent 001 or +1 so the binary point needs to shift 1 to the right. And the second exponent is 3 to the right. These are the two numbers re-aligned, the numbers have to start with a 0 because the original numbers are positive and they have to remain positive.

            01.000      (which is 1)
           011.1    -   (which is 3 1/2)

Next pad them out with zeroes

             001.000  
             011.100   -

Now to do the subtraction, the bottom number needs to be converted into its two compliment. The quick way to do this is to flip all the bits after the rightmost 1, but leave that 1 unchanged and so the number 011.100 becomes 100.100

Add them using the rules 0+0 = 0, 1 + 0 = 1, 1+1 = 0 carry 1, 1+1+1 = 1 carry 1.

             001.000  
             100.100   +
                  -------------
             101.100  

This is in twos compliment, use a binary table to work out its value

-4 2 1 1/2 1/4
1 0 1 1 0

This is -4 + 1 + 1/2 = -2 1/2 which is correct as 1 - 3.5 = -2.5

For a negative number to be normalised, it needs to start with 10, which it is, and also the binary point needs to be between the 10 pattern. The result above needs the point moved two to the left and so the exponent has to have +2 in it.

The final answer is (with mantissa and exponent)

             1.01100   010