1

My daughter is studying computing at university - as I'm a programmer she is coming to me for help but I'm struggling with some of the maths she is asking me.

She's asking me for help in converting 0.9 in binary to decimal form. First I had an issue as 0.9 isn't actually representable in binary accurately - but now her tutor has advised to use 0.1110012 as an approximation.

I can convert this in excel or in python, but to show her how to do it by hand is beyond me. Can someone help with a simple explainer to me that I can relay?

Max
  • 11
  • 1
  • 2
  • 1
    http://www.wolframalpha.com/input/?i=0.9+in+binary (Just to save people time in the future) –  May 09 '18 at 17:01
  • 3
    Notice that $1/2 + 1/4 + 1/8 < 0.9$ but $1/2 + 1/4 + 1/8 + 1/16 > 0.9$, so we should use $0.111_2$ as an approximation. Now refine it and look at $1/2 + 1/4 + 1/8 + 1/32$, and so on. –  May 09 '18 at 17:01
  • 2
    If you asked me to convert $0.1$ in binary to decimal form, I would say the answer is $0.5$, since each represents the fraction one half. But since $9$ is not a binary digit, I don't understand what it means to convert $0.9$ "in binary" to decimal form. – Barry Cipra May 09 '18 at 17:26
  • 3
    "converting 0.9 in binary to decimal form". Are you sure you don't mean "converting 0.9 in decimal to binary form" The latter is expressing $0.9_{10}$ as $0.abcd...{2}$. the former is expressing $0.9{2}$ as $0.abcd...{10}$. As $9 \ne 0$ and $9 \ne 1$ the former doesn't make any sense whatsoever. However the latter as $0.111001001001....{2}$ does. – fleablood May 09 '18 at 17:28

6 Answers6

2

In theory, binary expansions and decimal expansions are the same. To wit:

$n = 0.a_1a_2a_3....._{10} = \sum\limits_{k = 1}^{\infty} a_k \frac 1{10^k}$ for $a_k\in\{0,1,.... 9\}$.

And $n = 0.b_1b_2..... _{2} = \sum\limits_{k = 1}^{\infty} b_k \frac 1{2^k}$ for $b_k \in \{0,1\}$.

If $n \not \in \mathbb Q$ then the decimal and the binary expansion is infinitely long and does not repeat periodically.

If $n = \frac pq\in \mathbb Q$ and if $q|10^m$ for some $m$ then the decimal expansion will terminate after at most $m$ terms. Otherwise the decimal expansion is infinite but repeats for a period of at most $q$ terms.

And if $q|2^m$ for some $m$ then the binary expansion will .... ditto ...

And to write $m = \frac 57$ or $n = \frac 9{10}$ as decimal or binary is more or less the same.

Base 10: If $m = \frac 57$ we see that $\frac 57 < 1$ so we multiply by $10$ and get $\frac {50}{7} = 7\frac 1{7}$ so $a_1 = 7$.

Base 2: If $n = \frac 9{10}$ we see that $\frac 9{10} < 1$ so we multiply by $2$ and get $\frac {18}{10} = 1\frac 45$ so $b_1 = 1$.

Base 10: We take the remainder, $\frac 17$ and multiply by $10$. $\frac {10}7 = 1\frac 37$ so $a_2 = 1$.

Base 2: We take the remainder, $\frac 45$ and multiply by $2$. $\frac {8}5 = 1\frac 35$ so $b_2 = 1$.

Base 10: we repeat indefinately. Remainder is $\frac 37$. We multply by $10$ and get $\frac {30}7 = 4\frac 27$ so $a_3=4$. $10*\frac 27 = \frac {20}7 = 2\frac 67$ so $a_4= 2$. $10*\frac 67=\frac {60}7 = 8\frac 47$ so $a_5 = 8$ etc.

Base 2: we repeat indefinately. Remainder is $\frac 36$. We multply by $2$ and get $\frac {6}5 = 1\frac 15$ so $b_3=1$. $2*\frac 15 = \frac 25 = 0\frac 67$ so $b_4= 0$. $2*\frac 25=\frac {4}5 = 0\frac 45$ so $b_5 = 0$ etc.

[Note: this is easier than decimal expansion because we never actually have to divide anything. We just need to test if values are great or less than $1$.

Base 10: we continue until with either get a remainder $0$ or if we get are remainder we had before. $10*\frac 47 = \frac {40}7 = 5\frac 57$ so $a_6 = 7$. But $\frac 57$ is where we started. This is an infinite loop. $m= \frac 57 = 0.714285\overline{714285}$.

Base 2: we continue until with either get a remainder $0$ or if we get are remainder we had before. $2*\frac 45 = \frac 85 = 1\frac 35$ so $b_6 = 1$. $2*\frac 35 = \frac 65 = 1\frac 15$ so $b_7 = 1$. But we had $\frac 15 $ back when we calculated $b_3$. We are now in an infinite loop. $n = \frac 9{10} = 0.1110011\overline{0011}$.

Now just to hammer this home:

We can verify our answers.

$m = 0.714285\overline{714285}$

$10^6m = 714285.714285\overline{714285}$

$999999m= 714285$

$m = \frac {714285}{999999} = \frac {5*142857}{7*142857} = \frac 57$.

$n = .111001100110011...$

$2^4n = 1110.0110011....$

$(2^4-1)n= 1101.1$

$(15n)*2 = 11011_2 = 27$

$n = \frac {27}{30} = \frac 9{10}$.

fleablood
  • 124,253
0

You can evaluate the term like $$ (0.d_1 d_2 d_3 \dotsb)_2 = \sum_{k=1}^{\infty} d_k 2^{–k} = \sum_{k=1}^{\infty} \frac{d_k}{2^{k}} $$ so $$ (0.111001)_2 = \frac{1}{2}+\frac{1}{4}+\frac{1}{8}+\frac{1}{64}= \frac{32+16+8+1}{64}= \frac{57}{64}= 0.890625 $$ The precise binary representation of $0.9$ has infinite many digits $$ (0.1\overline{1100})_2 = (0.1)_2 + (0.0\overline{1100})_2 = \frac{1}{2} + \frac{1}{2} (0.\overline{1100})_2 = \\ \frac{1}{2} + \frac{1}{2} \left( 12 \sum_{k=1}^{\infty} \frac{1}{16^k}\right) = \frac{1}{2} + 6 \left( -1 + \frac{1}{1–\frac{1}{16}} \right) = \frac{1}{2} +\frac{6}{15} = \frac{9}{10} = 0.9 $$ where the bars indicate repetition and we used the formula for a geometric series $$ \sum_{k=0}^{\infty} q^k = \frac{1}{1-q} \quad (\lvert q \rvert < 1) $$

mvw
  • 34,562
0

Here a kind of pseudo-code / recursion:

Let $r_0\in [0,1)$, say $r_0 = 0.9_{10}$. For $k = 1, 2, \dotsc$ let $$ d_k = \operatorname{floor}(2 \cdot r_{k-1}) $$ and $$ r_k = 2\cdot r_{k-1} - d_k.$$ Then, $$ r_0 = \sum_{k=1}^\infty d_k 2^{-k} = (0.d_1d_2\dotsc)_2. $$

user251257
  • 9,229
0

Let's try thinking in base two. Note first that

$${1\over101}=0.001100110011\ldots$$

because $100\times0.001100110011\ldots=0.110011001100\ldots$ so that

$$101\times0.001100110011\ldots=0.110011001100\ldots+0.001100110011\ldots=0.111111111111\ldots=1$$

(in the same way that $0.9999999999\ldots=1$ in base ten). It follows that

$${1\over1010}=0.0001100110011\ldots$$

and thus

$${1001\over1010}=1-{1\over1010}=0.1110011001100\ldots$$

Barry Cipra
  • 79,832
0

Fractions in decimal lead to repeating decimals. We get things like $$ 10^3 \equiv -1 \pmod {37} \; , $$ $$ 10^6 \equiv 1 \pmod {37} \; , $$ $$ \frac{1}{37} = 0.0270270270270...$$ Here, $2^4 \equiv 1 \pmod 5$ and $$ \frac{1}{5} = \frac{\frac{3}{16}}{\frac{15}{16}} = \frac{\frac{3}{16}}{1 -\frac{1}{16}} $$ The point is that you know how to do this denominator as a repeating binary, $$ \frac{1}{1 -\frac{1}{16}} = 1 + \frac{1}{16} + \frac{1}{16^2} + \frac{1}{16^3} ... $$ or binary $$ 1.000100010001000100010001 \ldots $$ So that is decimal $16/15.$ You also know how to write $3/16$ $$ 0.0011 $$ so that $1/5$ becomes binary $$ 0.0011001100110011001100110011.. $$ and one tenth becomes binary $$ 0.00011001100110011001100110011.. $$ Next, decimal 9 is binary $$ 1001 $$ and we need to multiply with possible carries to get decimal 9/10.

Will Jagy
  • 139,541
0

The solution is more compact if we first do the problem in octal, then convert the answer to binary. So note that $0.9 = 9/10_{dec} = 11/12_{oct}$. Then apply the long division algorithm, but do all the arithmetic in octal. This requires that you be able to multiply (by a single digit) and subtract in octal. $$ \require{enclose} \begin{array}{r} 0.714 \\[-3pt] 12 \enclose{longdiv}{11.000} \\[-3pt] \underline{10.6 \phantom{0} \phantom{0}}\\[-3pt] 20 \phantom{0} \\[-3pt] \underline{12 \phantom{0}} \\[-3pt] 60 \\[-3pt] \underline{50} \\[-3pt] 10 \\[-3pt] \end{array} $$ So $11/12_{oct} \approx 0.714_{oct}$.

Conversion from octal to binary is easy: $0.714_{oct} = 0.111001100_{bin}$.

Alternative methods are to do everything in hexadecimal, which is yet more compact, but I find it harder to multiply and subtract in hexadecimal than in octal; or to do everything in binary, but binary requires a lot more writing, which makes for more chances to make mistakes, at least for me.

awkward
  • 14,736