# How does conversion from fixed-point to floating-point happen?

I came across to the code that convert 32-bit signed fixed-point number (16.16) to a float and it looks like (pseudocode)

floating = fixed / 65536.0


Could you please explain me what's the essence of dividing by this? Why does this dividing works when fixed-point and floating-point numbers have different internal structures?

## 1 Answer

Your code converts a fixed-point number into its value. It also works for converting a fixed-point number to a rational number, for example.

A fixed-point number of the form $16.16$ consists of 32 binary digits, the first 16 to the left of the decimal dot, the second 16 to its right. When you insert the decimal dot, you are dividing by $2^{16} = 65536$.

Here is a decimal example. Consider a number stored in decimal fixed-point $2.2$. What is the value of the number stored as $1234$? It is $12.34 = 1234/100$.

• Excuse me, what do you mean by inserting the decimal dot? I'm confused a little, I thought the decimal/binary dot is kind of imaginary thing. Oct 15, 2017 at 13:45
• It's not imaginary at all. It's implicitly there. Check out my decimal example. Oct 15, 2017 at 13:47
• Well, we have 10^2 instead 2^16 in your decimal example. It seems like this value (10^2 or 2^16) looks like a scaling factor, am I right? Oct 15, 2017 at 13:51
• Right - fixed point stores fractional values by scaling and rounding them. Oct 15, 2017 at 13:54