Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I want to know the algorithm of converting a given float (e.g, 3.14) to binary in the memory.

I read this wikipedia page, but it only mentions about the conversion the other way.

Let me quickly give the details, from the same wikipedia page:

32 bit floating point representation

As you know; the floating number is calculated as:

$value = (-1)^ {sign} \times 2^{exponent-127} \times fraction $


$ exponent = 2^2 + 2^3 + 2^4 + 2^5 + 2^6 $

$ fraction = 1 + 2^{-2} $

in this example. Please check the wikipedia page for more detailed info.

So, we can calculate the float number with given binary but how can we do the other way algorithmically?

Thanks in advance.

share|improve this question
In what way the input is given? –  dtldarek May 19 '12 at 12:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.