
#include "fxttypes.h"

ulong
mixedradix2num(const ulong *x, const ulong *m1, ulong n)
// Convert n-digit mixed radix number in x[] to (unsigned) integer.
// Radices minus one (that is, "nines") must be given in m1[].
{
    ulong r = 0;
    ulong p = 1;  // multiplier

    for (ulong k=0; k<n; ++k)
    {
        ulong t = x[k];
        r += p*t;
        p *= m1[k]+1;  // nines are given
    }

    return r;
}
// -------------------------

void
num2mixedradix(ulong N, ulong *x, const ulong *m1, ulong n)
// Convert N to n-digit mixed radix number in x[].
// Radices minus one (that is, "nines") must be given in m1[].
{
    for (ulong k=0; k<n; ++k)
    {
        ulong t = (m1[k]+1);  // nines are given
        x[k] = N % t;
        N /= t;
    }
}
// -------------------------

