# Infinite base two number to base ten

Suppose I have a base two number that repeats itself every five places (a number $x$ such that $0\le x<1$. For example:

$$x=0.101011010110101101011010110101101011010110101...$$

x={1,0,1,0,1}


Then, thinking of this five number list as repeating itself forever, use Mathematica to change it to a base 10 number.

Update: My question came as a result of @Kagaratsch's answer at Using a piecewise defined sequence, find all $x_0$. Thanks to @Xavier's answer, now I can do this:

mytup = Tuples[{0, 1}, 5]
FromDigits[{{#}, 0}, 2] & /@ Most[mytup]

• {1, 0, 1, 0, 1}. (2)^Range[0, 4]/(2^5 - 1) //N – Michael E2 Dec 7 '15 at 3:22
• NSum[{1, 0, 1, 0, 1}. (2)^-Range[n + 1, n + 5], {n, 0, Infinity, 5}] – Michael E2 Dec 7 '15 at 3:24
• @MichaelE2 Great answer. Thanks. – David Dec 7 '15 at 3:48
• @MichaelE2 better still, your expression with plain Sum produces the exact 21/31 result. – george2079 Dec 7 '15 at 18:07
• @george2079 Yeah, I realized that, but I thought the question asked for numerical, decimal result. I suppose RealDigits@Sum[{1, 0, 1, 0, 1}. (2)^-Range[n + 1, n + 5], {n, 0, Infinity, 5}] or {1, 0, 1, 0, 1}. (2)^Range[0, 4]/(2^5 - 1) // RealDigits might be more in line with @David's question. – Michael E2 Dec 7 '15 at 21:54

You can use

FromDigits[{{{1, 0, 1, 0, 1}}, 0}, 2]


where {1, 0, 1, 0, 1} is the infinite repeating part, 0 the length of the integer part, and 2 the base in which the number is given. The output will be given in base ten.

FromDigits[{{{1, 0, 1, 0, 1}}, 0}, 2]
(* 21/31 *)

• Wow! Haven't seen this one before. Thanks. – David Dec 7 '15 at 3:49
• See my update to my original post. Thanks to you, I found this idea in the documentation. – David Dec 7 '15 at 3:57

It should be clear that if x = 0.101011010110101.... then 2^5 x = 10101.1010110101... so 32 x - x = 10101 = 21, then x = 21/31.