4
$\begingroup$

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 $

where

$ 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.

  • 0
    In what way the input is given?2012-05-19
  • 0
    Your question is unclear and there is a serious risk of confusion. What is the input representation, among decimal [with fractional part] and IEEE single-precision floating-point ? What is the output representation, among binary integer and string of 0/1 [or other] ?2015-12-28

4 Answers 4