# Can decimal be represented in binary?

There's one YouTube video (Conversion Of Fractions From Base Ten To Other Bases) and it shows how to convert a fraction (7/8) to base 2. So then he converts it to a decimal (0.875) and then to base 2 and he gets 0.111. When I try putting 0.875 on a base converter http://jalu.ch/coding/base_converter.php, I end up getting 0.111, but when I do it on another convert. On the same website, if I try 7/8, it doesn't allow it. On another website http://www.cleavebooks.co.uk/scol/calnumba.htm, if I try 7/8 or 0.875, it doesn't allow it.

There was another question https://stackoverflow.com/questions/1089018/why-cant-decimal-numbers-be-represented-exactly-in-binary about why decimals can't be represented in binary, but I still don't understand it.

So what I want to know is, can you really represent a decimal or fraction in binary? From the video, the answer is 0.111, but in the converter, it's 0.111. Why is that? It seems as though you can only represent decimals or fractions in binary by doing it manually. Can you have 0.(something)(something) in binary? I thought binary was supposed to be 1s and 0s. Why 0.111?

Edit 1: Thanks for correcting me with 7/8 = 0.111

• Yes you can, but if the denominator of the fraction's simplest form is not a power of $2$, then the binary representation is infinite. – barak manos Dec 18 '16 at 6:01
• It doesn't answer your question but here's a trick: Since $8 = 2^3$, and you know that $7 = 111_2$, that means that $\frac78 = 0.111_2$ for the same reason that $5/1000 = 0.005$ in base $10$ (dividing by $1000 = 10^3$ tells you to move the decimal $3$ places to the left; same with $8 = 2^3$, in binary). – pjs36 Dec 18 '16 at 6:11
• $\frac 78 = 0.875$ decimal. – Joffan Dec 18 '16 at 6:14
• The rules for binary work beyond the decimal point also: \begin{aligned} 0.1_2 & = \frac{1}{2} \\ 0.01_2 & = \frac{1}{4} \\ 0.001_2 & = \frac{1}{8} \\ \vdots \end{aligned} So take any decimal number and decompose it as sum of fractions of powers of two $x=\sum_{i=1} \frac{c_i}{2^i}$ and the coefficients $c_i$ are your binary digits. – ja72 Dec 18 '16 at 8:35

Whatever the vid says, any real number can be represented in binary. It may or may not have a "zero tail", but it is always possible. Same for any base, not just binary.

• By zero tail, you mean the 0.(something)(something)? – rumpled105 Dec 18 '16 at 6:52
• @rumpled105 I think they mean what is sometimes called a "terminating" decimal; so $7/8 = 0.111_2$ and has only finitely many places, whereas something like $1/3 = 0.010101..._2$ would have an infinitely repeating binary representation (just like it does in base $10$). – pjs36 Dec 18 '16 at 19:01
• Rememeber in decimal there are three possibilities: i) the decimal terminates (if and only if the denominator has only 2 or 5 as prime factors) ii) the decimal cycles periodically forever (only if it is rational and the denominator has a prime fact other than 2 or 5) or iii) it never repeats and never terminates. The same is true for binary.. i) it will terminate (iff the denominator only has 2 a prime factor. ex. 9/16 = .1001 = 1/2 + 1/16. ii) it will cycle. ex. 3/7 = .011011011011.... (I think) or iii) will never terminate or repeat (iff irrational). – fleablood Dec 18 '16 at 19:11
• @fleablood : In fact there are two possibilities: (i) the number is rational, in which case it has a cycling tail (this includes the case that the cycling part is "$\cdots 0-0-0-0-0\cdots$", which incidentally can always be written as a nonzero cycling tail: in decimal, "$1.0-0-0-0\cdots$" is identical to "$0.9-9-9-9-9\cdots$"); or (ii) the number is irrational, in which case it does NOT have a cycling tail. (cont'd) – MPW Dec 19 '16 at 13:49
• @fleablood : (cont'd) The subcase of (i) in which some positive power of the base times the number is an integer is precisely when there are two distinct representations, one with a "zero tail" and the other with a periodic tail whose cycle is the single largest digit. – MPW Dec 19 '16 at 13:50

In order to get the successive digits after the radix point in any base, multiply the numerator by the base and divide by denominator, the whole-number quotient being the next digit and the remainder being the new numerator:

\begin{array}{|c|c|} \hline \text{Numerator} & \text{Denominator} & \text{Quotient = Digit} & \text{Remainder} \\ \hline 7 & 8 & \color{red}{0.} & 7 \\ 2\cdot 7 = 14 & 8 & \color{red}{1} & 6 \\ 2\cdot 6 = 12 & 8 & \color{red}{1} & 4 \\ 2\cdot 4 = 8 & 8 & \color{red}{1} & \fbox 0 \\ \hline\end{array}

7/8=0.875 not 0.785. http://jalu.ch/coding/base_converter.php gets 0.875 to be 0.111