Moving from one numeral system to another...

Hi.

Hope it's the right place to post it (if not - please move it to the right forum).

I have a question regarding the transfer between numeral systems.

the way to convert, for example, the binary number $\displaystyle 101011001_{2}$ to decimal will be:

$\displaystyle 101011001_{2}= 1\cdot 2^8+0\cdot 2^7+1\cdot 2^6+0\cdot 2^5+1\cdot 2^4+1\cdot 2^3+0\cdot 2^2+0\cdot 2^1+1\cdot 2^0=345_{10}$

and, if I want to go back to a binary number:

$\displaystyle 345_{10} : 2 = 172_{10}$ , $\displaystyle r=1_{2}$

$\displaystyle 172_{10} : 2 = 86_{10}$ , $\displaystyle r=0_{2}$

$\displaystyle 86_{10} : 2 = 43_{10}$ , $\displaystyle r=0_{2}$

$\displaystyle 43_{10} : 2 = 21_{10}$ , $\displaystyle r=1_{2}$

$\displaystyle 21_{10} : 2 = 10_{10}$ , $\displaystyle r=1_{2}$

$\displaystyle 10_{10} : 2 = 5_{10}$ , $\displaystyle r=0_{2}$

$\displaystyle 5_{10} : 2 = 2_{10}$ , $\displaystyle r=1_{2}$

$\displaystyle 2_{10} : 2 = 1_{10}$ , $\displaystyle r=0_{2}$

$\displaystyle 1_{10} : 2 = 0_{10}$ , $\displaystyle r=1_{2}$

concatenating all the remainders togather, we'll get: $\displaystyle 101011001_{2}$

now, I do understand the logic behind this operations, but one thing is bothering me:

let's say I want to convert the same binary number to a 5-based (or even a 6 or a 7-based) number.

the only way to do it is to first convert $\displaystyle 101011001_{2}$ to $\displaystyle 345_{10}$ with the same method above, and only then to convert $\displaystyle 345_{10}$ to $\displaystyle 2340_{5}$ (using the second method, with the remainders).

Why isn't there a way to directly convert $\displaystyle 101011001_{2}$ to $\displaystyle 2340_{5}$?

What is stoping me from doing that?

Hope the the question is clear enough.

thanks in advanced.

Re: Moving from one numeral system to another...

Quote:

Originally Posted by

**Stormey** Hi.

Hope it's the right place to post it (if not - please move it to the right forum).

I have a question regarding the transfer between numeral systems.

the way to convert, for example, the binary number $\displaystyle 101011001_{2}$ to decimal will be:

$\displaystyle 101011001_{2}= 1\cdot 2^8+0\cdot 2^7+1\cdot 2^6+0\cdot 2^5+1\cdot 2^4+1\cdot 2^3+0\cdot 2^2+0\cdot 2^1+1\cdot 2^0=345_{10}$

and, if I want to go back to a binary number:

$\displaystyle 345_{10} : 2 = 172_{10}$ , $\displaystyle r=1_{2}$

$\displaystyle 172_{10} : 2 = 86_{10}$ , $\displaystyle r=0_{2}$

$\displaystyle 86_{10} : 2 = 43_{10}$ , $\displaystyle r=0_{2}$

$\displaystyle 43_{10} : 2 = 21_{10}$ , $\displaystyle r=1_{2}$

$\displaystyle 21_{10} : 2 = 10_{10}$ , $\displaystyle r=1_{2}$

$\displaystyle 10_{10} : 2 = 5_{10}$ , $\displaystyle r=0_{2}$

$\displaystyle 5_{10} : 2 = 2_{10}$ , $\displaystyle r=1_{2}$

$\displaystyle 2_{10} : 2 = 1_{10}$ , $\displaystyle r=0_{2}$

$\displaystyle 1_{10} : 2 = 0_{10}$ , $\displaystyle r=1_{2}$

concatenating all the remainders togather, we'll get: $\displaystyle 101011001_{2}$

now, I do understand the logic behind this operations, but one thing is bothering me:

let's say I want to convert the same binary number to a 5-based (or even a 6 or a 7-based) number.

the only way to do it is to first convert $\displaystyle 101011001_{2}$ to $\displaystyle 345_{10}$ with the same method above, and only then to convert $\displaystyle 345_{10}$ to $\displaystyle 2340_{5}$ (using the second method, with the remainders).

Why isn't there a way to directly convert $\displaystyle 101011001_{2}$ to $\displaystyle 2340_{5}$?

What is stoping me from doing that?

Hope the the question is clear enough.

thanks in advanced.

It is because you are used to dealing with base-10 numbers. You don't even realize that you are actually going through the same process when you convert to base-10 that you did to convert to base-2.

The expression $\displaystyle 101011001_{2}= 1\cdot 2^8+0\cdot 2^7+1\cdot 2^6+0\cdot 2^5+1\cdot 2^4+1\cdot 2^3+0\cdot 2^2+0\cdot 2^1+1\cdot 2^0$ is not in base-10. You then have to add everything up and put it in base-10. You find it easy to add things this way because you are used to base-10 operations. If you were used to adding numbers in other bases, you might just as easily dismiss the following addition: $\displaystyle 345_{10} = 3\cdot 10^2 + 4\cdot 10^1 + 5\cdot 10^0 = 3_5\cdot (20_5)^{2_5} + 4_5\cdot (20_5)^{1_5} + 10_5\cdot (20_5)^{0_5} = 2340_5$. This process is the exact same process you used for converting the binary number to base-10, but it might not look right because it is not in base-10. In base-10, the process we are taught for addition is to add up a column of digits, record the units place of the sum and "carry" the rest of the digits one column to the left. This is the same as taking the remainder when the sum is divided by 10.

So, you can certainly convert directly from one base to another, so long as you are comfortable with the arithmetic operations of that base.

Edit -- Here is an example of going from base-2 to base-7 without stopping at base-10:

$\displaystyle \begin{align*}(2_7)^{0_7} & = 1_7 \\ (2_7)^{1_7} & = 2_7 \\ (2_7)^{2_7} & = 4_7 \\ (2_7)^{3_7} & = 11_7 \\ (2_7)^{4_7} & = 22_7 \\ (2_7)^{5_7} & = 44_7 \\ (2_7)^{6_7} & = 121_7 \\ (2_7)^{10_7} & = 242_7 \\ (2_7)^{11_7} & = 514_7 \\ \\ 101011001_2 & = 1_7\cdot (2_7)^{11_7} + 0_7\cdot (2_7)^{10_7} + 1_7\cdot (2_7)^{6_7} + 0_7\cdot (2_7)^{5_7}+1_7\cdot (2_7)^{4_7}+1_7\cdot (2_7)^{3_7}+0_7\cdot (2_7)^{2_7}+0_7\cdot (2_7)^{1_7}+1_7\cdot (2_7)^{0_7} \\ & = 514_7 + 121_7 + 22_7 + 11_7 + 1_7\end{align*}$

$\displaystyle \begin{matrix} \scriptstyle{1} & \scriptstyle{1} & \scriptstyle{1} & \\ & 5 & 1 & 4_7 \\ & 1 & 2 & 1_7 \\ & & 2 & 2_7 \\ & & 1 & 1_7 \\ + & & & 1_7 \\ \hline 1 & 0 & 0 & 2_7\end{matrix}$

Re: Moving from one numeral system to another...

Brilliant.

Just the answer I was looking for (it didn't occur to me that the **arithmetic** itself also needs to be converted to the new base...).

Thanks, SlipEternal.

Just one more thing:

Quote:

Originally Posted by

**SlipEternal** If you were used to adding numbers in other bases, you might just as easily dismiss the following addition: $\displaystyle 345_{10} = 3_5\cdot (20_5)^2 + 4_5\cdot (20_5)^1 + 10_5\cdot (20_5)^0 = 2340_5$.

Shouldn't it be $\displaystyle 345_{10} = 3_5\cdot (10_5)^2 + 4_5\cdot (10_5)^1 + 10_5\cdot (10_5)^0 = 2340_5$,

since the number inside the parentheses is the base to which we are converting?

Re: Moving from one numeral system to another...

Quote:

Originally Posted by

**Stormey** Shouldn't it be $\displaystyle 345_{10} = 3_5\cdot (10_5)^2 + 4_5\cdot (10_5)^1 + 10_5\cdot (10_5)^0 = 2340_5$,

since the number inside the parentheses is the base to which we are converting?

In base-5, the number $\displaystyle 10$ is $\displaystyle 2\cdot 5 = 2\cdot 10_5 = 20_5$.

Edit: This might help visualize what is happening a little better:

$\displaystyle 345_{10} = 3\cdot 10^2 + 4\cdot 10^1 + 5\cdot 10^0 = 3_5\cdot (20_5)^{2_5} + 4_5\cdot (20_5)^{1_5} + 10_5\cdot (20_5)^{0_5} = 2340_5$

Also, I updated my post above to include an example of converting directly from base-2 to base-7.

Re: Moving from one numeral system to another...