7

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

What would be a cool way to start with:

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]
David
  • 14,883
  • 4
  • 44
  • 117
  • 3
    {1, 0, 1, 0, 1}. (2)^Range[0, 4]/(2^5 - 1) //N – Michael E2 Dec 07 '15 at 03:22
  • 3
    NSum[{1, 0, 1, 0, 1}. (2)^-Range[n + 1, n + 5], {n, 0, Infinity, 5}] – Michael E2 Dec 07 '15 at 03:24
  • @MichaelE2 Great answer. Thanks. – David Dec 07 '15 at 03:48
  • @MichaelE2 better still, your expression with plain Sum produces the exact 21/31 result. – george2079 Dec 07 '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 07 '15 at 21:54

2 Answers2

9

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 *)
2

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.

John McGee
  • 2,538
  • 11
  • 15