Loading...
Read a half-precision floating-point value by separating its sign, biased exponent and stored fraction. Establish the format before doing any arithmetic.
What you'll be able to do
Pearson’s International A-level uses IEEE 754 half precision, also called binary16. Its sixteen bits comprise one sign bit, five exponent bits and ten stored fraction bits. Group a bit string as s | EEEEE | FFFFFFFFFF before reading its value. The exponent field is an unsigned integer with bias 15; it is not a five-bit two’s-complement number.
For a normal finite value, exponent codes 1 through 30 represent powers −14 through 15. Subtract 15 from the stored exponent E to find the actual exponent. The sign bit selects a positive or negative value; a negative value is not obtained by complementing all sixteen bits. These rules belong to this format and must not be replaced by another board’s signed-mantissa model.
For a normal value, the significand is 1.f in binary. Only the fraction after the point is stored, because the leading 1 is implied. If the ten-bit fraction field has unsigned integer value F, that fraction is F/1024. There are therefore eleven significant binary digits of precision for a normal number, although only ten fraction bits appear in the stored field.
Use the place values 1/2, 1/4, 1/8 and so on to read the fraction directly. With stored fraction 0100000000, the restored significand is 1.01₂, equal to 1.25. With exponent field 10010₂=18, its scale is 2³. A sign bit of 1 gives −1.25×8=−10. Check the magnitude before applying the sign.
Exponent codes 00000 and 11111 have special meanings. Do not feed either into the normal-value formula with an implied leading 1. The next lesson on limits explains zeros, subnormals, infinities and NaNs. A reliable conversion begins with field boundaries and exponent classification, continues with the significand and scale, and ends with a sign and reasonableness check.
A useful check is that a normal significand lies from 1 inclusive to 2 exclusive. With actual exponent 3, its positive magnitude must lie from 8 inclusive to 16 exclusive. A claimed result of 0.625 for those fields is inconsistent. Practise both reading a supplied sixteen-bit string and assembling the fields from a labelled table.
| Field | Stored bits | Meaning |
|---|---|---|
| Sign | 1 | Negative |
| Exponent | 10010 | 18 − 15 = 3 |
| Fraction | 0100000000 | 1/4; restored significand 1.25 |
| Value | 1 | 10010 | 0100000000 | −10 |
Attempt the task before opening its worked response. Record each change of state, explain the rule used, and check the result against the original requirements. Code examples labelled Python 3 use that language’s conventions; pseudocode states its own assumptions.
Equation recap
Common mistakes to avoid
Key takeaways
Test yourself
Answer a few questions, then review anything you missed.
Start with the quiz above to check the key ideas. You can also choose another topic from the practice library.