Hello to all C++ expect programmer, i would like to create a function that multiply two integer which stored in char * or string.

As far as i know, 1234 * 4567 will be split into two parts which are1. compute x1y1, call the result A

2. compute x2y2, call the result B

3. compute (x1 + x2)(y1 + y2), call the result C

4. compute C - A - B; this number is equal to x1y2 + x2y1.

BigInteger multiply(BigInteger a, BigInteger b) {

int n = max(number of digits in a, number of digits in b)

if(n == 1) {

return a.intValue() * b.intValue();

} else {

BigInteger aR = bottom n/2 digits of a;

BigInteger aL = top remaining digits of a;

BigInteger bR = bottom n/2 digits of b;

BigInteger bL = top remaining digits of b;

BigInteger x1 = Multiply(aL, bL);

BigInteger x2 = Multiply(aR, bR);

BigInteger x3 = Multiply(aL + bL, aR + bR);

return x1 * pow(10, n) + (x3 - x1 - x2) * pow(10, n / 2) + x2;

}

}

A(1) = 12, A(2) = 34, B(1) = 45, B(2) - 67;

First, A = A(1) * B(1), then

B= B(1), B(2), then

C=( A(1) + B(1) * B(1) + B(2) );

The question is i don't understand the last statement.

What this does ?Code:return x1 * pow(10, n) + (x3 - x1 - x2) * pow(10, n / 2) + x2;

This is my code so far :

I not asking you all do for me but explanation and guideline is more than enough.Code:/* Polynomial is a expression with non negative integer power, 1 or more variable and costant(coefficient) Polynomial is important for signal processing, crytography and coding theory. Polynomial is core of multiplication algorithm in computing Karatsuba algorithm consits of many branches and optmization such as 1. KA for Degree-1 Polynomials - x ^ 1 2. Recursive KA for Polynomials of Degree 2i ¡ 1 - Efficient for coeficient power of 2 3. One-Iteration KA for Polynomials of Arbitrary Degree 4. KA for Degree-2 Polynomials - X ^ 2 5. KA for Polynomials of Arbitrary(Any) Degree Ratio between long multiplication and karatsuba > 3, then use KA for Degree-2 Polynomials Improvement of KA with dummy coefficient = 0 2. 1. compute x1y1, call the result A 2. compute x2y2, call the result B 3. compute (x1 + x2)(y1 + y2), call the result C 4. compute C - A - B; this number is equal to x1y2 + x2y1. BigInteger multiply(BigInteger a, BigInteger b) { int n = max(number of digits in a, number of digits in b) if(n == 1) { return a.intValue() * b.intValue(); } else { BigInteger aR = bottom n/2 digits of a; BigInteger aL = top remaining digits of a; BigInteger bR = bottom n/2 digits of b; BigInteger bL = top remaining digits of b; BigInteger x1 = Multiply(aL, bL); BigInteger x2 = Multiply(aR, bR); BigInteger x3 = Multiply(aL + bL, aR + bR); return x1 * pow(10, n) + (x3 - x1 - x2) * pow(10, n / 2) + x2; } } */ /* MS Calling Convention __cdecl, __fastcall, __stdcall; */ #include <iostream> #include <string> #include <sstream> #include <vector> using std::cout; using std::cin; using std::string; using std::stringstream; using std::vector; #define SIZE 50 // ------------------------------------------------ void MultiplyBigInteger(char *, char *); int length(char *); void divide(int, int *, int *); // ------------------------------------------------ int main(int argc, char *argv[]) { char *firstNumber = "99999", *secondNumber = "99999"; MultiplyBigInteger(firstNumber, secondNumber); return 0; } // ------------------------------------------------ void MultiplyBigInteger(char *firstNumber, char *secondNumber) { int firstLength = length(firstNumber); int secondLength = length(secondNumber); int *firstLeftLength = 0, *firstRightLength = 0, *secondLeftLength = 0, *secondRightLength = 0; char *firstRight = 0, *firstLeft =0, *secondRight = 0, *secondLeft = 0; divide(firstLength, firstLeftLength, firstRightLength); divide(secondLength, secondLeftLength, secondRightLength); if (firstLength == 1 && secondLength == 1) { } else { // MultiplyBigInteger( } } // ------------------------------------------------ int length(char *number) { int length = 0; for (int loop=0;number[loop] != '\0';loop++) { *(number + loop); length++; } return length; } // ------------------------------------------------ void divide(int length, int *leftLength, int *rightLength) { if (length % 2 != 0) { *leftLength = (length % 2) + 1; *leftLength = (length % 2); } else { *leftLength = length / 2; *rightLength = length / 2; } }

Thanks for your help.