Are you trying to find something like a form
a0 + a1 * (2^32) + a2 * (2^32)^2 + a3 * (2^32)^3 + ...
which is the definition of a base-2 32 system so ignore all the people who told you your question doesn't make sense!
In any case, what you are describing is called a basic transformation . There are quick ways, and there are simple ways to solve this problem. Quick methods are very complex (there are whole chapters of books devoted to this subject), and I am not going to consider them here (not least because I never tried to use them).
One easy way is to first implement two functions in your number system, multiplication and addition. (i.e. implement BigInt add(BigInt a, BigInt b) and BigInt mul(BigInt a, BigInt b) ). Once you decide this, you will notice that the base-10 number can be expressed as:
b0 + b1 * 10 + b2 * 10^2 + b3 * 10^3 + ...
which can also be written as:
b0 + 10 * (b1 + 10 * (b2 + 10 * (b3 + ...
therefore, if you move from left to right in your input line, you can delete one base digit 10 times at a time and use your add and mul functions to accumulate in your BigInt :
BigInt a = 0; for each digit b { a = add(mul(a, 10), b); }
Disclaimer: This method is not computationally efficient, but at least it will start.
Note. Converting from base-16 is much easier because 2 32 is an exact multiple of 16. Thus, the conversion basically comes before the bits are concatenated.
Oliver Charlesworth
source share