Arbitrary Base Conversion Create a routine that takes an array of blocks in one numeric base system, and convert them to an array of blocks in another numeric base system.  Both the from and to systems are arbitrary and should be accepted as a parameter.  The input array can be an arbitrary length (If using a language where array lengths are not stored with the array, such as C, a length parameter should be passed to the function).

Here's how it should work:

fromArray = [1, 1]
fromBase = 256
toBase = 16
result = convertBase(fromArray, fromBase, toBase);


Which should return [0, 1, 0, 1] or possibly [1, 0, 1] (leading 0s are optional since they don't change the value of the answer).

Here are some test vectors:


Identity Test Vector

fromArray = [1, 2, 3, 4]
fromBase = 16
toBase = 16
result = [1, 2, 3, 4]

Trivial Test Vector

fromArray = [1, 0]
fromBase = 10
toBase = 100
result = [10]

Big Test Vector

fromArray = [41, 15, 156, 123, 254, 156, 141, 2, 24]
fromBase = 256
toBase = 16
result = [2, 9, 0, 15, 9, 12, 7, 11, 15, 14, 9, 12, 8, 13, 0, 2, 1, 8]

Really Big Test Vector

fromArray = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
fromBase = 2
toBase = 10
result = [1, 2, 3, 7, 9, 4, 0, 0, 3, 9, 2, 8, 5, 3, 8, 0, 2, 7, 4, 8, 9, 9, 1, 2, 4, 2, 2, 3]

Non-even Base Vector

fromArray = [41, 42, 43]
fromBase = 256
toBase = 36
result = [1, 21, 29, 22, 3]



Other criteria / rules:


All integer variables should fit within a standard 32 bit signed integer for all sane input ranges.
You may convert to an intermediary representation, as long as the intermediary is nothing more than an array of 32 bit signed integers.
Expect to handle bases from 2 through 256.  There isn't any need to support higher bases than that (but if you would like to, by all means).
Expect to handle input and output sizes at least up to 1000 elements.  A solution that scales to 2^32-1 elements would be better, but 1000 is just fine.
This isn't necessarily about having the shortest code that will meet these rules.  It's about having the cleanest and most elegant code.


Now, this isn't exactly trivial to do, so an answer that almost works might be accepted!
Python
# divides longnum src (in base src_base) by divisor
# returns a pair of (longnum dividend, remainder)
def divmod_long(src, src_base, divisor):
  dividend=[]
  remainder=0
  for d in src:
    (e, remainder) = divmod(d + remainder * src_base, divisor)
    if dividend or e: dividend += [e]
  return (dividend, remainder)

def convert(src, src_base, dst_base):
  result = []
  while src:
    (src, remainder) = divmod_long(src, src_base, dst_base)
    result = [remainder] + result
  return result