How does one convert a decimal float to binary using the multiply by 2 method?

Click For Summary

Discussion Overview

The discussion revolves around the conversion of decimal floating-point numbers to binary using the multiply by 2 method. Participants explore the representation of numbers in floating point format, specifically addressing the example of converting the decimal number 0.1 into its binary equivalent.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant questions how the representation of 0.1 as approximately 1.1001100110011001100 × 2^-4 is derived, expressing confusion over the method used in the example from the text.
  • Another participant asserts that converting the binary float of the mantissa to decimal yields 1.5999999, which when divided by 16 approximates 0.1, suggesting the book's answer is correct.
  • A participant explains that to achieve a binary mantissa of 1.something, one must determine the appropriate power of 2 to multiply 0.1, leading to the conclusion that the binary exponent is -4.
  • Another participant confirms that the conversion site provides the same result as the book when converting 0.1 to normalized binary scientific notation.
  • One participant presents a mathematical breakdown of the binary expansion of 0.1, detailing a series of transformations that lead to the binary representation.

Areas of Agreement / Disagreement

Participants express varying levels of understanding regarding the conversion process, with some asserting the correctness of the book's example while others remain uncertain about the method. The discussion does not reach a consensus on the clarity of the conversion technique.

Contextual Notes

Some participants reference external tools and methods for conversion, indicating potential discrepancies in results and interpretations. The discussion highlights the complexity of floating point representation and the nuances involved in converting decimal to binary.

CGandC
Messages
326
Reaction score
34
I've started reading A concise introduction to numerical analysis, A.C. Foul and on the first page there's the following paragraph about how a floating point in fixed point precision can be represented:

We live in a continuous world with infinitely many real numbers. However, a computer has only a finite number of bits. This requires an approximate representation. In the past, several different representations of real numbers have been suggested, but now the most widely used by far is the floating point representation. Each floating point representations has a base ##\beta## (which is always assumed to be even) which is typically 2 (binary), 8 (octal), 10 (decimal), or 16 (hexadecimal), and a precision ##p## which is the number of digits (of base ##\beta## ) held in a floating point number. For example, if ##\beta=10## and ##p=5##, the number 0.1 is represented as ##1.0000 \times 10^{-1}##. On the other hand, if ##\beta=2## and ##p=20##, the decimal number 0.1 cannot be represented exactly but is approximately ##1.1001100110011001100 \times 2^{-4}##. We can write the representation as ##\pm d_0 . d_1 \cdots d_{p-1} \times \beta^e##, where ##d_0 . d_1 \cdots d_{p-1}## is called the significand (or mantissa) and has ##p## digits and ##e## is the exponent. If the leading digit ##d_0## is non-zero, the number is said to be normalized. More precisely ##\pm d_0 . d_1 \cdots d_{p-1} \times \beta^e## is the number
##
\pm\left(d_0+d_1 \beta^{-1}+d_2 \beta^{-2}+\cdots+d_{p-1} \beta^{-(p-1)}\right) \beta^\epsilon, 0 \leq d_i<\beta
##

I don't understand the example where it says " ##\beta=2## and ##p=20##, the decimal number 0.1 cannot be represented exactly but is approximately ##1.1001100110011001100 \times 2^{-4}## " . How did the author arrive to ##1.1001100110011001100 \times 2^{-4}##?

I've tried arriving to the result using a method ( I don't know how it's called, I've met in on the internet so I have no idea about its correctness ) in which one keeps multiplying the number after the decimal point by 2 and if it goes past 1.0 then we add 1 to the output, else we add 0 to the output. Also, using a decimal float to binary converter on the web such as on the site https://www.exploringbinary.com/floating-point-converter/ , doesn't give me the author's result.
 
  • Like
Likes   Reactions: pbuk
Computer science news on Phys.org
Well if I take the binary float of the mantissa above and convert it to decimal, I get 1.5999999, which when divide by 16 give 0.1 to 6 digits. So the answer in the book is correct. One way to look at it is that in floating point you want the binary mantissa to be 1.something. So what power of 2 do you need to multiply 0.1 by to give a binary mantissa that is 1.something?
0.4 = 0.0110011...
0.8 = 0.110011...
1.6 = 1.100110011...
3.2 = 11.00110011...

So this fixes the binary exponent as -4. Then you convert 1.6 to binary and you get the result above.
 
  • Like
Likes   Reactions: CGandC
Also, on the conversion site you linked, if you convert the decimal 0.1 to Normalized binary scientific notation, you get the result in the book.
 
Understood, thanks!. I missed the result at the site, sorry, my bad.
 
Note that the binary expansion of 0.1 can be obtained as \begin{split}<br /> \frac{1}{10} &amp;= \frac{3}{30} \\<br /> &amp;= \frac12 \cdot \frac{3}{15} \\<br /> &amp;= \frac12 \cdot \frac{3}{16} \cdot \frac{16}{15} \\<br /> &amp;= \frac{3}{32} \left(1 + \frac{1}{16} + \frac{1}{16^2} + \dots \right) \\<br /> &amp;= 2^{-5} \times (11.0011001100110011\dots)_2 \\<br /> &amp;= (1.100110011001100\dots)_2 \times 2^{-4}. \end{split} The basis of the technique is to ensure that the denominator is either 2^n, in which case the expansion terminates, or else has a factor of 2^n - 1 in which case the expansion eventually repeats, using <br /> \frac{1}{2^n - 1} = 2^{-n} \frac{1}{1 - 2^{-n}} = 2^{-n}(1 + 2^{-n} + 2^{-2n} + \dots).
 
  • Like
Likes   Reactions: phyzguy and CGandC

Similar threads

  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
5K
Replies
6
Views
10K
Replies
6
Views
5K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K