title: BBP algorithm get nth digit of PI?
body: <p>I am trying to turn the <a href="http://mathworld.wolfram.com/BBPFormula.html" rel="nofollow noreferrer">BBP Formula (<em>Bailey-Borwein-Plouffe</em>)</a> in to C# code, it is digit extraction of pi in base 16 (<em>spigot algorithm</em>), the idea is give the input of what index/decimal place you want of pi then get that single digit. Let's say I want the digit that are at the decimal place/index 40000 (in base 16) without having to calculate pi with 40000 decimals because I don't care about the other digits.</p>
  
  <p>Anyhow here is the math formula, (<em>doesn't look like it should be to much code?</em> )</p>
  
  <p><a href="https://i.stack.imgur.com/48WsS.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/48WsS.gif" alt="enter image description here"></a></p>
  
  <p>Can't say I understand 100% what the formal mean, if I did I probably be able to make it in to code, but from my understanding looking at it.</p>
  
  <p><strong>Is this correct?</strong></p>
  
  <p><strong>pseudo code</strong></p>
  
  <blockquote>
    <p>Pi = SUM = (for int n = 0; n &lt; infinity;n++) {   SUM += ((4/((8*n)+1))
    - (2/((8*n)+4)) - (1/((8*n)+5)) - (1/((8*n)+6))*((1/16)^n)) }</p>
  </blockquote>
  
  <p>Capital sigma basically is like a "for loop" to sum sequences together?
  example
  <a href="https://i.stack.imgur.com/f8rRZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f8rRZ.png" alt="enter image description here"></a></p>
  
  <p>and in C# code:</p>
  
  <pre><code>static int CapSigma(int _start, int _end)
  {
      int sum = 0;
      for(int n = _start; n &lt;= _end; n++)
      {
          sum += n; 
      }
      return (sum);
  }
  </code></pre>
  
  <p><strong>Code so far</strong> <em>(not working)</em>:</p>
  
  <pre><code>static int BBPpi(int _precision)
  {
      int pi = 0;
      for(int n = 0; n &lt; _precision; n++)
      {
          pi += ((16 ^ -n) * (4 / (8 * n + 1) - 2 / (8 * n + 4) - 1 / (8 * n + 5) - 1 / (8 * n + 6)));
      }
      return (pi);
  }
  </code></pre>
  
  <p>I'm not sure how to make it in to actual code also if my pseudo code math is correct?</p>
  
  <p>How to sum 0 to infinity? Can't do it in a for loop and also where in the formula is the part ("input") that specify what nth (index) digit you want to get out? is it the start n (n = 0)? so too get digit 40000 would be n =40000?</p>