Loading...
Convert the magnitude to binary, normalise it, and construct the three fields. Keep an independent decoding check so a correct-looking bit pattern cannot hide a misplaced point.
What you'll be able to do
Record the sign, then work with the positive magnitude. Convert the integer part using powers of two or repeated division. For a fractional part, repeatedly multiply the remaining fraction by two; each integer part becomes the next binary digit. For 0.375 the steps produce 0, 1, 1, giving 0.011₂. Stop when the remaining fraction reaches zero, or retain sufficient extra digits if rounding will be required.
Combine the parts before normalising. For 6.375, the result is 110.011₂. Move the point two places left to write 1.10011₂×2². Moving the point left produces a positive exponent; moving it right for a magnitude below one produces a negative exponent. Normalisation changes the representation, not the numerical value.
For −6.375 the sign bit is 1. The actual exponent 2 becomes stored code 2+15=17, which is 10001₂ in five bits. Remove the implied leading 1 and store the following fraction 10011, padding on the right to ten places: 1001100000. Padding on the left would change the fraction’s place values.
The complete encoding is 1 | 10001 | 1001100000. Decode it as −(1+1/2+1/16+1/32)×4=−6.375. Keep exactly five exponent bits and ten fraction bits, including leading and trailing zeroes. Writing the fields separately during working makes it easier to find an arithmetic error than immediately writing a long unlabelled word.
For 0.15625, the exact binary fraction is 0.00101₂=1.01₂×2⁻³. The biased exponent is −3+15=12, giving 01100; the fraction field is 0100000000. Since the sign is positive, the complete word is 0 | 01100 | 0100000000. A normal exponent may be negative even though its stored code is an unsigned positive integer.
The small Python check below uses the standard library’s half-precision format e and explicit big-endian byte order >. It is a teaching verification tool, not an extra practical-exam API to memorise. It prints the actual stored bits, rather than assuming that Python’s ordinary float variable is itself binary16. Values needing more precision must be rounded, which is treated separately.
import struct
for value in (-6.375, 0.15625):
word = int.from_bytes(struct.pack('>e', value), 'big')
bits = f'{word:016b}'
print(bits[0], bits[1:6], bits[6:])Scroll horizontally to see the full code or table.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.
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.