0
$\begingroup$

Sincere salutations everyone. I would like to to encode 7/8 into Binary floating point. I know that 7/8 is .111 in Binary. However, how would I go about finding the exponent and the Mantissa for the value? I know the sign bit would be 0 (as it is positive). How many spaces would I move the decimal point? Thanks!

$\endgroup$
1
$\begingroup$

Assuming a standard IEEE 32 bits we have:

  • 8 bits of exponents
  • 23 bits of mantissa
  • 1 bit of sign

Your expansion $0.111$ is correct however we must normalize it such that there is a $1$ in front of the decimal point. In this case we will multiply it by $2$ (which as in base $10$ shifts the number toward the left).

Therefore $0.111 = 0.111 \cdot 2^1 \cdot 2^{-1} = (0.111 \cdot 2^1) \cdot 2^{-1} = 1.11 \cdot 2^{-1}$.

Now you can extract the sign-bit which is $0$, the exponent which is $-1$ (remember to apply the bias of $+127$) and the mantissa which is obtained by discarding the $1$ in front of the decimal point and keeping only the decimal. In this case the mantissa is $11000000000000000000000$.

$\endgroup$
2
  • $\begingroup$ Excellent post, but let's say we want to use 8 bits, 1 sign bit, 3 exponent bits and 4 mantissa bits. What would one do? $\endgroup$ – pr0grammeur Jan 30 '17 at 13:28
  • $\begingroup$ The idea is exactly the same, the only thing that would change would be the bias of the exponent. In this case the bias would be $2^2 -1$. Therefore $0.111 \implies 0|1100|010$ $\endgroup$ – Zubzub Jan 30 '17 at 14:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.