I was challenged by one of my fellow students to write a mini-library in the programming language called C that enables you to work with very large numbers (the numbers that the language offers natively have a maximum value they can hold).
After defining what a big number is, I have to re-define the basic operations such as addition and multiplication for these big numbers that I am creating. I've written algorithms for computing the sum and product, but I am stuck on calculating powers.
What efficient algorithms are there for computing powers of two numbers on paper, that I can then translate into code? (My base will always be an integer and my exponent will always be a positive integer.)
fast exponentiation is defined as follows:
$x^\frac{n}{2}$ and $x^{(n-1)}$ are computed recursively, for $a^2$ you can program a function $^2$ as follow $a= a_1^k+a_2$ where $k$ is the half of the length of $a$
$$a^2= (a_1)^2 10^2k+ 2*a_1*a_2 1°^k +a_2)^2$$
where $(a_1)^2$ and $(a_2)^2$ are computed recursively.