Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using a mixed-base number to represent some data. E.g. $4_6 3_6 2_6 0_3 1_3 2_3$. As you can see the bases for the first and last 3 numbers are 6 and 3 respectively.

In the past, this number had the same base (6), so it was just a matter of converting from base 6 to base 10 and I was guaranteed a unique number in base 10 for a corresponding number in base 6.

I'd like to avoid setting up a hash table where the string 432012 maps to (say) 1342.

Now, I'm trying to figure out how to do the same for this mixed-base number ; any suggestions?

Would this work?

$$4_6 3_6 2_6 0_3 1_3 2_3 = 4 \cdot 6^5 + 3 \cdot 6^4 + 2 \cdot 6^3 + 0 \cdot 3^2 + 1 \cdot 3^1 + 2 \cdot 3^0$$

share|cite|improve this question
up vote 1 down vote accepted

With your approach, numbers from $27=1+2_32_32_3$ to $215=1_60_30_30_3-1$ are not representable. I would do $4_63_62_60_31_32_3\ \ $ as $4\cdot 6^2\cdot 3^3 + 3\cdot 6^1 \cdot 3^3 +2\cdot 6^0 \cdot 3^3 + 0\cdot 3^2+1\cdot 3^1 +2\cdot 3^0=4433.\ \ $ You have to carry from each position with its particular base. Then all numbers will be representable.

share|cite|improve this answer
Great! $555222$ corresponds to 5831 which is correct since there are a total of 5832 permutations. – Jacob Aug 8 '11 at 19:14

The method is essentially the same as for a fixed base. The expression $$4_63_62_60_31_32_3$$ represents $$4\cdot 6^5 + 3\cdot 6^4 +2\cdot 6^3 + 0\cdot 3^2+1\cdot 3^1 +2\cdot 3^0.$$

Conversion to base $10$ is now just a calculation. I get $35429$ (the answer is given so that you can check). If there are significant length chunks to the same base, there are tricks to speed up the computation. But in the sort of application you mention, the powers that might be needed should be stored as constants.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.