title: Multiplying integers the long way
body: <p>I'm trying to create long int multiplication function. In math for multiplying 2 numbers for example 123 X 456, I do:</p>
  
  <pre><code>(12 * 10^1 + 3)( 45 * 10^1 + 6) = 
  (540 * 10^2) + (72 * 10^1) + (135 * 10^1) + 18 = 15129
  </code></pre>
  
  <p>I created a small program for this algorithm but it didn't work right.</p>
  
  <p>I don't know where my problem is. Can you help me to understand and correct that?</p>
  
  <p>Tnx</p>
  
  <pre><code>int digits(int n) {
      int digit = 0;
      while (n&gt;0){
          n/=10;
          digit++;
      }
      return digit;
  }
  
  long int longMult(long int a, long int b) {
      long int x,y,w,z;
      int digitA = digits(a);
      int digitB = digits(b);
  
      if((a==0) || (b==0)) {
          return 0;
      } else if (digitA &lt; 2 || digitB &lt; 2) {
          return a*b;
      } else {
          int powA = digitA / 2;
          int powB = digitB / 2;
  
          //for first number
          x = a/(10^powA);
          y = a%(10^powA);
  
          //for second number
          w = b/(10^powB);
          z = b%(10^powB);
  
          return ( longMult(x,w)*(10^(powA*powB)) + longMult(x,z) +
                   longMult(w,y)*(10^(powA*powB)) + longMult(y,z));
      }
  }
  
  int main()
  {
      cout &lt;&lt; digits(23) &lt;&lt; endl; // for test
      cout &lt;&lt; longMult(24,24); // must be 576 but output is 96
      return 0;
  }
  </code></pre>