Take the 2-minute tour ×
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.

How can I convert a number from one base, $b_1 \neq 10$ to another base $b_2 \neq 10$ without going through base $10$ i.e. $b_1\rightarrow 10 \rightarrow b_2$?

share|improve this question

2 Answers 2

up vote 5 down vote accepted

Short answer: You can do it, but you have to do arithmetic in base $b_1$. If you're using a computer, it's easy. If you are using pencil-and-paper, it may be easier to convert through base 10.


The algorithm to convert a number $x$ to base $b$ is:

  1. Set $n = 0$
  2. Divide $x$ by $b$, yielding a quotient $q$ and a remainder $r$
  3. Digit $r_n$ of the answer is $r$
  4. If $q = 0$, halt; the answer is $r_{n}r_{n-1}\ldots r_0$.
  5. Set $x = q$, $n = n+1$ and return to step 2

Let's say you want to convert 1e6 (base 17) to base 7.

We set $x = $ 1e6 and $n=0$. We divide $x$ by 7, yielding a quotient of 48 and a remainder of 1, so $r_0 = 1$ and return to step 2.

Now we divide 48 by 7, yielding a quotient of a and a remainder of 6, so $r_1 = 6$ and we return to step 2.

Now we divide a by 7 yielding a quotient of 1 and a remainder of 3, so $r_2 = 3$ and we return to step 2.

Now we divide 1 by 7 yielding a quotient of 0 and a remainder of 1, so $r_3 = 1$ and since $q=0$ we halt.

The answer is $1361_7$.

share|improve this answer
    
but this is because the computer can do mathematical operation in base $16$. Can I do the inverse of what you did with a computer i.e. converting from base $7$ to base $16$ without going through decimal? –  user31280 Feb 25 '13 at 14:33
    
I didn't use a computer; I did it by hand using my brain and a piece of paper. I will redo the example converting from base 17 so that you are not confused. –  MJD Feb 25 '13 at 14:37
    
sorry, my bad. How did you divide 1e7 by 7 in base $16$? –  user31280 Feb 25 '13 at 14:41
    
I used the usual short division algorithm for base 10, but in base 16 instead. 1e divided by 7 is 4 with a remainder of 2; 47 divided by 7 is a with a remainder of 1, so the quotient is 4a and the remainder is 1. –  MJD Feb 25 '13 at 14:43
1  
It means the quotient without the remainder. The remainder is $r$. –  MJD Apr 2 '13 at 2:14

If you can do arithmetic in base $b_1$, you can use the technique of repeatedly dividing by $b_2$ and reading off the remainders in reverse order. For example to convert $261_{\text{seven}}$ to base four, you can carry out the following calculation (which is entirely in base seven):

$$\begin{align*} 261&=4\cdot50+1\\ 50&=4\cdot11+3\\ 11&=4\cdot2+0\\ 2&=4\cdot0+2 \end{align*}$$

Thus, $261_{\text{seven}}=2031_{\text{four}}$.

To see why it works, imagine that we’ve already written the number in base four. The remainder after division by four is just the unit’s (= least significant) digit, and the integer quotient is what’s left when that digit is removed.

For the reverse conversion, done entirely in base four:

$$\begin{align*} 2031&=13\cdot110+1\\ 110&=13\cdot2+12\\ 2&=13\cdot0+2 \end{align*}$$

Of course the middle digit has to be written $6$ in base seven instead of the base four $12$, but we get $2031_{\text{four}}=261_{\text{seven}}$, as expected.

share|improve this answer

Your Answer

 
discard

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