Base N to Base N Conversion

  • #1
mepcotterell
21
0
I know how to convert from any base to any other base but to do so I usually have to go through base 10 with the exception of base 2 to base 16 and vise-versa. I was wondering if you guys know an easy way to convert bases?

The way I usually do it is using the base notation to get base 10 then the remainder method to finish the conversion...

For example to go from base 2 to 5 I would do this...

1011b2 to b10

1*2^0 + 1*2^1 + 0*2^2 + 1*2^3 = 1 + 2 + 0 + 8 = 11

11b10 to b5

11 / 5 = 2 R 1
2 / 5 = 0 R 2

= 21b5
 
Last edited:

Answers and Replies

  • #2
NateTG
Science Advisor
Homework Helper
2,452
7
If you're converting between two bases that are both powers of the same number, then it's possible to do it in 'chunks' because there are locations that have corresponding 'orders'. Consider, for example that the digits base 4 are:
1, 4, 16, 64, and so on
while the digits base 2 are
1,2,4,8,16,32,64 and so on
So it's possible to do 'local' conversion:
Effectively a number base for can be thought of as a polynomial
[tex]\sum a_i 4^i[/tex]
but that's
[tex]\sum a_i \left(2^2\right)^i[/tex]
so
[itex]\sum a_i 2^{2i}[/itex]
and, since [itex]0\leq a_i \leq 3[/itex] we have
[tex]a_i=b_{2i}*2^0+b_{2i+1}*2^i[/tex]
so the sum is
[itex]\sum (b_{2i}*2^0+b_{2i+1}*2^i)2^{2i}[/tex]
distribute through
[itex]\sum b_{2i}^{2i}+b_{2i+1}2^{2i+1}[/itex]
but that readily regroups to
[itex]\sum b_{i}2^i[/itex]

It's a little bit more complicated if you look at, for example, base [itex]9=3^2[/itex] and base [itex]27=3^3[/itex]:
[tex]\sum b_{3i} 9^i + b_{3i+1} 9^{3i+1} + b_{3i+2}9^{3i+2}=\sum c_{2j} 27^{2j} + c_{2j+1} 27^{2j+1}[/itex]
(This is similar to converting from base 9 to base 9^3=729=27^2 to base 27)

Generally, there is no need to convert numbers to base 10 in order to do base conversion, but, since we're familiar with arithmetic in base 10, that's our normal tendency. Similarly, computers, when doing arithmetic computers typically convert into and out of a base that's some power of two because computers can operate on binary (or hexidecimal) numbers more efficiently. This will look a bit strange, but consider your example:

Convert
1011 (base 2)
to base 5
Now
2^1=1 (base 5)
2^2=4 (base 5)
2^3=13 (base 5)
2^4=31 (base 5)

Then:
[tex]1101 (base 2) = 1*2^4+1*2^3+0*2^2+1*2^0 (base 5) = 1*31 + 1* 13 + 0 * 4 + 1 * 1 (base 5)[/tex]
[tex]=31+13+1 (base 5)=44+1 (base 5)=100 (base 5)[/tex]
 

Suggested for: Base N to Base N Conversion

  • Last Post
Replies
1
Views
98
  • Last Post
Replies
33
Views
2K
  • Last Post
Replies
5
Views
680
Replies
25
Views
796
Replies
3
Views
496
Replies
12
Views
1K
Replies
3
Views
964
  • Last Post
Replies
9
Views
1K
  • Last Post
Replies
8
Views
457
  • Last Post
Replies
8
Views
762
Top