title: Converting a big integer to decimal string
body: <p>At the risk of having this question voted as a duplicate, or even to have it closed, I had this question has come up.</p>
  
  <p><strong>Background</strong></p>
  
  <p>In "normal" data types such as int, long long, etc..., to convert from the binary numeric value to a decimal string, you would do the following (in pseudo code):</p>
  
  <pre><code>Set length = 0
  Set divisor to largest base10 value the data type will hold (Divisor).
    Loop
      Divide number in question by divisor.
      Place result in a string at position length.
      Increment the length by 1.
      Divide the divisor by 10.
  Reverse the string.
  Print the string.
  </code></pre>
  
  <p>The actual implementation in (most) any language is quite trivial.</p>
  
  <p><strong>The Problem</strong></p>
  
  <p>The issue that I am encountering with the above method is that with big integer numbers (also known as <em>arbitrary precision arithmetic</em>), there is no largest base 10 value to start with.  So the question is "How do you initialize the divisor to the largest possible base10 value if there is no way to know what that value is?"</p>
  
  <p><strong>What I Have Tried</strong></p>
  
  <p>Still trying to draft a solution.</p>
  
  <p><strong>Research</strong></p>
  
  <p>Some of the links that I have found here include the following:</p>
  
  <p><a href="https://stackoverflow.com/questions/16965915/convert-a-big-hex-number-string-format-to-a-decimal-number-string-format-w">Convert a &quot;big&quot; Hex number (string format) to a decimal number (string format) without BigInteger Class</a></p>
  
  <p><a href="https://stackoverflow.com/questions/4361441/c-print-a-biginteger-in-base-10">C: print a BigInteger in base 10</a></p>
  
  <p><a href="https://stackoverflow.com/questions/13154304/fastest-way-to-convert-a-biginteger-to-a-decimal-base-10-string">Fastest way to convert a BigInteger to a decimal (Base 10) string?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/16965915/convert-a-big-hex-number-string-format-to-a-decimal-number-string-format-w">Convert a &quot;big&quot; Hex number (string format) to a decimal number (string format) without BigInteger Class</a></p>
  
  <p>A Google search turned up other things, but nothing that specifically answers my question.</p>
  
  <p><strong>Ideas</strong></p>
  
  <p>One method that I think that <strong>might</strong> work is as follows (in pseudo code):</p>
  
  <pre><code>Define p_divisor as previous divisor.
  Set divisor = 1
    Loop:
      if divisor &lt; dividend
        then
          Set p_divisor = divisor
          divisor = divisor * 10
        else
          end loop
    Loop:
      Divide number in question by divisor.
      Place result in a string at position length.
      Increment the length by 1.
      Divide the divisor by 10.
      if divisor == 1 then end loop
  Reverse the string.
  Print the string.
  </code></pre>
  
  <p>Would this be the correct way?  I have a big integer library up and working (including multiplication and division) so it wouldn't be that hard to pull this off.  The big issue that I see with this method is performance, because you have to run a multiplication sequence to get the initial divisor, then you have to divide twice for each base10 position.  One for the actual division, and the other for the divisor.</p>