3.2.1 Converting Integers

One of the topics I’ve found rather difficult teaching to students is the concept of changing bases. It seems that students have the concept of a base-10 system so ingrained in their mind (almost always unbeknownst to them) that it is difficult considering other base systems. Hopefully this section will be a good introduction to the process of changing bases and doing basic operations in other number systems. First, let’s observe how we look at numbers in the usual base-10 fashion.

Everyone knows that 1254 means that you have one-thousand, two-hundred, and fifty-four of something, but expressing this in an unusual manner we can say:

1294=11000+2100+510+41=1103+2102+9101+41001294 = 1 \cdot 1000 + 2 \cdot 100 + 5 \cdot 10 + 4 \cdot 1 = 1 \cdot 10^3 + 2 \cdot 10^2 + 9 \cdot 10^1 + 4 \cdot 10^0

From this we can see where this concept of “base-10” comes from, we are adding combinations of these powers of tens (depending on what 090 - 9 digit we multiply by). So, you can express any integer nn in base-10 as:

n=am10m+am110m1+am210m2+a1101+a0100n = a_m \cdot 10^m + a_{m-1}10^{m-1} + a_{m-2} \cdot 10^{m-2} + \dots a_1 \cdot 10^1 + a_0 \cdot 10^0

Where all ama_m’s are integers ranging from 090 - 9.

The fact that we are summing these various powers of 10 is completely an arbitrary one. We can easily change this to some other integer (like 6 for example) and develop a base-6 number system. Let’s see what it would look like:

n=am6m+am16m1+am26m2+a161+a060n = a_m \cdot 6^m + a_{m-1}6^{m-1} + a_{m-2} \cdot 6^{m-2} + \dots a_1 \cdot 6^1 + a_0 \cdot 6^0

Where all ama_m’s are integers ranging from 050 - 5.

So to use an example, let look at what the number 1236123_6 (where the subscript denotes we are in base-6) would look like in our usual base-10 system:

1236=162+261+360=136+26+31=36+12+3=5110123_6 = 1 \cdot 6^2 + 2 \cdot 6^1 + 3 \cdot 6^0 = 1 \cdot 36 + 2 \cdot 6 + 3 \cdot 1 = 36 + 12 + 3 = 51_{10}

From this we have found the way to convert any base-n whole number to base-10!

Let’s look at another example:

33214=343+342+241+140=364+316+24+11=192+48+8+1=249103321_4 = 3 \cdot 4^3 + 3 \cdot 4^2 + 2 \cdot 4^1 + 1 \cdot 4^0 = 3 \cdot 64 + 3 \cdot 16 + 2 \cdot 4 + 1 \cdot 1 = 192 + 48 + 8 + 1 = 249_{10}

So now that we know how to convert from base-n to base-10, let’s look at the process on how to convert the opposite direction:

  1. Find the highest power of nn which divides the base-10 number (let’s say it is the mm-th power).
  2. Figure out how many times it divides it and that will be your (m+1)(m + 1)-th digit in base-n.
  3. Take the remainder and figure out how many times one less than the highest power divides it (so see how many times nm1n^{m-1} divides it). That is your (m)(m)-th digit.
  4. Take the remainder, and continue process.

I know that this might seem complicated, but let’s look at an example we have already done in the “forward” direction to illustrate how to go “backwards.” Convert 511051_{10} to base-6:

  1. Well we know 62=366^2 = 36 and 63=2166^3 = 216, so the highest power which divides 51 is 626^2.
  2. 36 goes into 51 one time, so our 3rd digit is 1.
  3. The remainder when dividing 51 by 36 is 15.
  4. Now we see how many times 616^1 goes into 15 (which is 2 times, so our 2nd digits is 2).
  5. The remainder when dividing 15 by 6 is 3.
  6. 60=16^0 = 1 divides 3 obviously 3 times, so our 1st digit is 3
  7. So after conversion, 5110=123651_{10} = 123_6, which corresponds to what we expected.

As a warning, some digits might be zero when you do the base conversion. Let’s look at an example of this: Convert 181018_{10} to base-4:

42=164^2 = 16 and 43=644^3 = 64, so 42=164^2 = 16 goes into 18 once with a remainder of 2: Third Digit is 1 Now 41=44^1 = 4 doesn’t go into 2: Second Digit is 0 404^0 goes into 2 twice: First Digit is 2 Answer: 1024102_4

This seems like a lot of steps in making a base conversion, but after substantial practice, it will become second nature. Here are some practice problems with just converting bases from base-n to base-10 and reverse.

Problem Set 3.2.1

2125=_10212_5 = \__{10}
108=_410_8 = \__{4}
20045=_102004_5 = \__{10}
34+3=_93_4 + 3 = \__{9}
24+2=_42_4 + 2 = \__{4}
82=_58_2 = \__{5}
43+4=_44_3 + 4 = \__{4}
24=_22_4 = \__{2}
33+3=_33_3 + 3 = \__{3}
48=_34_8 = \__{3}
43+23=_84^3 + 2^3 = \__{8}
24+1=_82^4 + 1 = \__{8}
20010=_7200_{10} = \__{7}
72+18+4=_67^2 + 18 + 4 = \__{6}
23410=_5234_{10} = \__{5}
1234=_10123_4 = \__{10}
25+2=_42_5 + 2 = \__{4}
43010=_5430_{10} = \__{5}
54010=_6540_{10} = \__{6}
243+27+3=_9243 + 27 + 3 = \__{9}
2005=_10200_5 = \__{10}
2006=_10200_6 = \__{10}
44+42+40=_44^4 + 4^2 + 4^0 = \__{4}
33+32+30=_33^3 + 3^2 + 3^0 = \__{3}
216+108+30+5=_6216 + 108 + 30 + 5 = \__{6}
44b=4044_b = 40, then b=b =
12310=_5123_{10} = \__{5}
1234=_5123_4 = \__{5}
82+24+40=_48^2 + 24 + 40 = \__{4}
2345=_4234_5 = \__{4}
686+98+14=_7686 + 98 + 14 = \__{7}
7710=_777_{10} = \__{7}
43+4=_84^3 + 4 = \__{8}
2345=_10234_5 = \__{10}
34+32+30=_33^4 + 3^2 + 3^0 = \__{3}
12310=_4123_{10} = \__{4}
125+75+15+1=_5125 + 75 + 15 + 1 = \__{5}
23410=_5234_{10} = \__{5}
1728+288+36+4=_121728 + 288 + 36 + 4 = \__{12}
128+48+12+2=_4128 + 48 + 12 + 2 = \__{4}
Find bb when 4b6=294b_6 = 29
456=_945_6 = \__{9}
2104=_6210_4 = \__{6}
438=_943_8 = \__{9}
345=_734_5 = \__{7}