Data representation · A level · OCR H446 1.4.1, AQA 7517 4.5.4.4, Eduqas A500QS 2.3 · about 35 min
Binary fractions, mantissa and exponent, normalisation, and adding floating point numbers.
[1 mark]An unsigned fixed point byte has 4 bits before the binary point and 4 after. What is the value of 10110110?
[1 mark]A floating point number has an 8-bit two's complement mantissa 01010000 and a 4-bit two's complement exponent 0011. What is its denary value?
[1 mark]A floating point number has an 8-bit two's complement mantissa 10100000 and a 4-bit two's complement exponent 0001. What is its denary value?
[1 mark]Which of these 8-bit two's complement mantissas are normalised?
Tick every answer that is true.
[1 mark]Normalise the floating point number with 8-bit mantissa 00011000 and 4-bit exponent 0011. Give the mantissa, a space, then the exponent.
[1 mark]Why are floating point numbers normalised?
Tick every answer that is true.
Write two functions.
- float_value(mantissa, exponent): mantissa is a string of 8 characters 0 or 1, a two's complement fixed point number with the binary point after the first bit (place values -1, ½, ¼ down to 1/128). exponent is a string of 4 characters 0 or 1, a two's complement integer from -8 to 7. It returns the value, mantissa × 2 to the power of exponent, as a float.
- is_normalised(mantissa): returns True when the first two bits of the mantissa are different, otherwise False.
The loop prints each line as 01101000 0011 = 6.5 normalised or 00011000 0101 = 6.0 not normalised, with the value exactly as Python prints the float.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def float_value(mantissa, exponent):
return 0.0
def is_normalised(mantissa):
return False
for mantissa, exponent in [("01101000", "0011"), ("10110000", "0010"), ("00011000", "0101"), ("11100000", "1111")]:
word = "normalised" if is_normalised(mantissa) else "not normalised"
print(mantissa, exponent, "=", float_value(mantissa, exponent), word)The hint students can ask for: The mantissa's place values start at -1 and then halve: 1/2, 1/4, 1/8 and so on. The exponent is an ordinary two's complement integer with -8 as its first place value. The value is the mantissa multiplied by 2 to the power of the exponent. A normalised mantissa's first two bits are different.
# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()
def float_value(mantissa, exponent):
m = -1.0 if mantissa[0] == "1" else 0.0
place = 0.5
for bit in mantissa[1:]:
if bit == "1":
m = m + place
place = place / 2
e = -8 if exponent[0] == "1" else 0
e = e + int(exponent[1:], 2)
return m * 2 ** e
def is_normalised(mantissa):
return mantissa[0] != mantissa[1]
for mantissa, exponent in [("01101000", "0011"), ("10110000", "0010"), ("00011000", "0101"), ("11100000", "1111")]:
word = "normalised" if is_normalised(mantissa) else "not normalised"
print(mantissa, exponent, "=", float_value(mantissa, exponent), word)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.