Portal:AOL-Files/Articles/Base X Tutorial
AOL-Files | Articles | Downloads | FDO91 | |
(Originally by AOL-Files staff member Tau)
Base x is a name I have given to any number using the base x. X can be any integer greater than 1. Base 2 is called binary, 10 is decimal, and 16 is hex. The concept of different bases is dificult to understand as well as to explain but I will teach it to the best of my ability. I had nothing better to do while sitting in math class so I taught myself how to do this. Therefore, not all of it is guaranteed to be correct, but it is accurate to the best of my knowledge. Plus, numbers cannot be false.
We are all familiar with base 10. To understand what this means pick any three digit number. For simplicity I will choose 123. In our heads we can automatically picture this as one hundred plus twenty plus three. Look at the following conversion:
1. | 123 | |
2. | 123 = | 100 + 20 + 3 |
3. | 100 + 20 + 3 = | (100 × 1) + (10 × 2) + (1 × 3) |
4. | (100 × 1) + (10 × 2) + (1 × 3) = | (10². × 1) + (10¹ × 2) + (10º × 3) |
The concept of base 10 is shown in the last step. Lets look at 123 in a different base. Replace the green number 10 with any number. To calculate 123 in base 6 you would do the following:
(6². × 1) + (6¹ × 2) + (6º × 3) = 51
51 equals 123 only if you think of 51 as using 6 as the base and 123 using 20 as the base. I write this as base10(123) = base6(51). Confused yet? Just wait.
Remember that all zeros at the beginning of a number are disregarded. For example, 00000016 is equal to 16. This is true with all bases.
Converting base 10 to another base
For now, only pick a base less than or equal to 10.
- Choose a decimal number that you want to convert and choose the base that you want to put it in.
I am going to convert 312 into base 7. - You need to find out how many digits long your answer will be. Begin with zero and keep taking your base to whatever power you are at until the number you get is greater than the number you want to convert. The power that makes the base greater than the number you want to convert is how many digits the answer will be. If you take your number to a certain power and it is exactly the number you are trying to convert then stop.
7º = 1. 1 < 312. Continue incrementing the power by one.
7¹ = 7. 7 < 312. Continue incrementing the power by one.
7². = 49. 49 < 312. Continue incrementing the power by one.
7³ = 343. 343 > 312. Stop. Answer will be 3 digits long. - ## Begin with the power one less than the number which brought you over and take your base to that power.
- Divide the number you want to convert by that number and round down to the nearest integer.
- Take the number you are converting and subtract the base multiplied by the previous number.
- Now take that result and divide it by the base you are using to the number of digits minus 2 power and round down to the nearest integer.
- Follow this pattern until your ramainder is 0.
Before you reread that look at the example.
{|
| Identification
| Take the base to one less than the last power you used. If its the first step then use one less than the number of digits.
| Divide the last remainder by the result of the previous step. If its the first step the the number you are trying to convert is the remainder.
| Round the result down to the nearest integer
| Take the remainder minus the previous answer times the answer in the first column. This will be the remainder used in the next loop.
|-
| 7 = base
2 = power
312 = remainder
6 = first digit of the final answer
18 = remainder to be used in next step
| 7². = 49
| 312 / 49 = 6.36...
| 6
| 312 - 6 * 7². = 18
|-
| 7 = base
1 = power
18 = remainder
2 = next digit of the final answer
4 = remainder to be used in next step
| 7¹ = 7
| 18 / 7 = 2.57...
| 2
| 18 - 2 * 7¹ = 4
|-
| 7 = base
0 = power
4 = remainder
4 = next digit of the final answer
0 = what the remainder must be to finish the problem
| 7º = 1
| 4 / 1 = 4
| 4
| 4 - 4 * 7º = 0
|}
And the final answer is the combination of the digits in the third column. The answer here is 624. Base10(312) = Base7(624).
Check the answer: (7². × 6) + (7¹ × 2) + (7º × 4) = 312.
Example Two
I am going to follow the same instructions as above to convert the number 540 into base 5.
- Converting 540 into base 5.
- 5º = 1. 1 is less than 540 so continue incrementing the power by one.
5¹ = 5. 5 is less than 540 so continue incrementing the power by one.
5². = 25. 25 is less than 540 so continue incrementing the power by one.
5³ = 125. 125 is less than 540 so continue incrementing the power by one.
5^4 = 625. 625 is greater than 540 so the answer will be 4 digits long. - Now follow the steps of step 3 above.{| width="60%"
| 5³ = 125 | 540 / 125 = 4.32 | Round down = 4 | 540 - 4 × 5³ = 40 |- | 5². = 25 | 40 / 25 = 1.6 | Round down = 1 | 540 - 1 × 5². = 15 |- | 5¹ = 5 | 15 / 5 = 3 | Round down = 3 | 15 - 3 × 5¹ = 0 |}
Since you have already reached 0 as a remainder without trying 5º you need to add one zero for every power that you have not tried yet until you reach 0. In this case 5º is the next power so you only need to add one zero to the answer. The answer is the third column is 413. Add the zero so the answer is 4130.
Check the answer: (5³ × 4) + (5². × 1) + (5¹ × 3) + (5º × 0) = 540.
Converting to a base greater than 10
A problem arrises when using a base greater than 10. Look at this example where I try to convert 209 to base 15:
15¹ = 15 | 209 / 15 = 13.33 | Round down = 13 | 209 - 13 × 15¹ = 14 |
15º = 1 | 14 / 1 = 14 | Round down = 14 | 14 - 1 × 15º = 5 |
The answer is the combination of the third column results. In this case 13 and 14. If you combine then the answer is 1314 but the problem is that 1314 cannot be distinguished as 13 and 14 or 1314. To correct this problem letters are used.
10 = A | 17 = H | 24 = O | 30 = U |
11 = B | 18 = I | 25 = P | 31 = V |
12 = C | 19 = J | 26 = Q | 32 = W |
13 = D | 20 = K | 27 = R | 33 = X |
14 = E | 21 = L | 28 = S | 34 = Y |
15 = F | 22 = M | 29 = T | 35 = Z |
16 = G | 23 = N |
Therefore, in the previous example the answer would be DE. So base15(209) = DE. To check this use the same steps as the others were checked: (15¹ × 13) + (15º × 14) = 209.
Converting into a base greater than 35 would require different identifiable characters.
Hex
Base 16 is called hex. Example: Convert 244 into hex.
16¹ = 16 | 244 / 16 = 15.25 | Round down = 15 | 244 - 15 × 16¹ = 4 |
15º = 1 | 4 / 1 = 4 | Round down = 4 | 4 - 4 × 15º = 0 |
15 is equal to F so the answer is F4.
This is the main reason why hex is so commonly used: there are 255 different characters and 16². = 256. Therefore, every character can be displayed as 2 digits, instead of 3. You just saw this when converting 244, which is 3 characters, into F4, which is 2 characters.
Binary
Binary is base 2. Example: Convert 212 into binary.
- Converting 212 into base 2.
- 2º = 1. 1 is less than 212 so continue incrementing the power by one.
2¹ = 2. 2 is less than 212 so continue incrementing the power by one.
2². = 4. 4 is less than 212 so continue incrementing the power by one.
2³ = 8. 8 is less than 212 so continue incrementing the power by one.
2^4 = 16. 16 is less than 212 so continue incrementing the power by one.
2^5 = 32. 32 is less than 212 so continue incrementing the power by one.
2^6 = 64. 64 is less than 212 so continue incrementing the power by one.
2^7 = 128. 128 is less than 212 so continue incrementing the power by one.
2^8 = 256. 256 is greater than 212 so the answer will be 8 digits long. - Convert it:
{| width="60%"
| 2^7 = 128 | 212 / 128 = 1.56... | Round down = 1 | 212 - 1 × 2^7 = 84 |- | 2^6 = 64 | 84 / 64 = 1.31... | Round down = 1 | 84 - 1 × 2^6 = 20 |- | 2^5 = 32 | 20 / 32 = .625 | Round down = 0 | 20 - 0 × 2^5 = 20 |- | 2^4 = 16 | 20 / 16 = 1.25 | Round down = 1 | 20 - 1 × 2^4 = 4 |- | 2³ = 8 | 4 / 8 = .5 | Round down = 0 | 4 - 0 × 2^3 = 4 |- | 2^2 = 4 | 4 / 4 = 1 | Round down = 1 | 4 - 1 × 2². = 0 |}
Since a remainder of zero was reached at 2². two zeros must be added to the result from the table. So the answer is 11010100. A further explanation of binary can be found at my binary tutorial.
Converting out of a different base
In all the checks above you have been converting out of a different base. Basically, to convert out of another base you start with the base to the zero power multiplied by the far right value of the number then move over one and increment the power by one and follow this until you finish the number.
Example. Base(9) of a number equals 74. What does this equal in base 10?
9º × 4 = 9 +
9¹ × 7 = 63 equals 72.
This is more aparent when you see how to find the value of a base 10 number. For example,
123 = (10º × 3) + (10¹ × 2) + (10². × 1).
With some more practice you'll get it. 10 + 10 = 4, right?