Wednesday, February 15, 2012

[igwlipho] Divide and conquer radix conversion

Suppose we wish to convert the large hexadecimal number 0x1234567890ABCDEF into decimal.

First convert 0x12345678 and 0x90ABCDEF into decimal recursively.

Also, convert 0x100000000 into decimal.  This can be computed by repeated squaring.  Memoize the partial powerings, as they are also needed for the recursive subproblems.

Multiply the decimal representations of 0x12345678 and 0x100000000 by your favorite subquadratic multiplication algorithm.  This is the weird step, as it needs to be done in base 10, not hexadecimal.  But if you have a subquadratic base-10 multiplication implementation lying around, then it begs the question, why not do the entire calculation (which created the starting large hexadecimal number) in base 10?

Add to the product the decimal representation of 0x90ABCDEF. Done.

Update: better method.

No comments :