title: How can I perform division in a program, digit by digit?
body: <p>I'm messing around with writing a class similar to mpz (C) or BigInteger (Java).  This is just for fun, so please don't go on about how I shouldn't be writing my own.</p>
  
  <p>I have a class similar to:</p>
  
  <pre><code>public class HugeInt
  {
      public List&lt;Integer&gt; digits;
  
      public HugeInt(String value)
      {
          // convert string value into its seperate digits. 
          // store them in instance variable above
      }
  }
  </code></pre>
  
  <p>Now, doing the add() and subtract() method of this class are pretty simple.  Here is an example:</p>
  
  <pre><code>private List&lt;Integer&gt; add(List&lt;Integer&gt; a, List&lt;Integer&gt; b)
      {
          List&lt;Integer&gt; smallerDigits = (compareDigits(a,b) &lt; 0) ? a : b;
          List&lt;Integer&gt; largerDigits = (compareDigits(a,b) &gt;= 0) ? a : b;
          List&lt;Integer&gt; result = new ArrayList&lt;Integer&gt;();
  
          int carry = 0;
  
          for(int i = 0; i &lt; largerDigits.size(); i++)
          {
              int num1 = largerDigits.get(i);
              int num2 = (i &lt; smallerDigits.size()) ? smallerDigits.get(i) : 0;
  
              result.add((num1 + num2 + carry) % 10);
              carry = ((num1 + num2 + carry) / 10);
          }
  
          if (carry != 0) result.add(carry);
  
          return result;
      }
  </code></pre>
  
  <p>Similarly, doing the multiply wasn't that hard either.</p>
  
  <p>I see on wikipedia there is a page on <a href="http://en.wikipedia.org/wiki/Division_(digital)" rel="noreferrer">Division Algorithms</a>, but I'm not sure which one is appropriate for what I'm trying to do.  </p>
  
  <p>Because these positive integers (represented as digits) can be arbitrarily long, I want to make sure I don't attempt to do any operations on anything other than digit-by-digit basis.</p>
  
  <p>However, can anyone point me in the right direction for doing a division of two numbers that are represented as <code>List<code>&lt;Integer</code>></code>'s? Also, I can ignore the remainder as this is integer division.</p>