Bytesize CS

Floating point

Score 0 / 0 Streak 0 Best 0

Write as normalised floating point

How floating point works

A floating point number has a mantissa and an exponent, both in two's complement. The binary point sits just after the first bit of the mantissa, so the mantissa's place values are −1, ½, ¼, ⅛ and so on. The exponent says how many places to move the binary point: right if it is positive, left if it is negative.

Normalised: the mantissa must start 01 (positive) or 10 (negative). This gives the most precision for the number of bits.

Floating point to denary:

  1. Work out the exponent in denary.
  2. Move the binary point that many places. Moving left, fill the gap with copies of the sign bit.
  3. Add up the place values of the 1s. The first bit is negative.

Denary to floating point:

  1. Write the number in fixed point binary. For a negative number, write the positive version, then flip the bits and add 1.
  2. Move the binary point to just after the first bit, where the first two bits are different. The number of places it moved left is the exponent (moving right gives a negative exponent).
  3. Pad the mantissa with 0s on the right, and write the exponent in two's complement.

Normalising: shift the mantissa left until the first two bits are different, filling with 0s on the right. Subtract the number of places shifted from the exponent.