Inter base conversion hints:
Counting in the various bases:
Each base has b unique digits to represent each number. These digits are used in each position to form the number. Let's count from 1 to twenty in each of the 4 bases so we can see how these digits are used.
|
Decimal |
Binary |
Octal |
Hex |
|---|---|---|---|
|
1 |
1 |
1 |
1 |
|
2 |
10 |
2 |
2 |
|
3 |
11 |
3 |
3 |
|
4 |
100 |
4 |
4 |
|
5 |
101 |
5 |
5 |
|
6 |
110 |
6 |
6 |
|
7 |
111 |
7 |
7 |
|
8 |
1000 |
10 |
8 |
|
9 |
1001 |
11 |
9 |
|
10 |
1010 |
12 |
A |
|
11 |
1011 |
13 |
B |
|
12 |
1100 |
14 |
C |
|
13 |
1101 |
15 |
D |
|
14 |
1110 |
16 |
E |
|
15 |
1111 |
17 |
F |
|
16 |
10000 |
20 |
10 |
|
17 |
10001 |
21 |
11 |
|
18 |
10010 |
22 |
12 |
|
19 |
10011 |
23 |
13 |
|
20 |
10100 |
24 |
14 |
Positional Notation:
This is the term that explains why the relative value of a digit depends on its the location of that digit within a series of numbers. The general formula for positional notation and place value is:
Bn ... B7 B6 B5 B4 B3 B2 B1 B0
Where B is the base, and B2 means squared or raised to the power of 2.
This translates into the following place values:
Binary: 28 27 26 25 24 23 22 21 20
decimal value 256 128 64 32 16 8 4 2 l this number 1 1 0 1 1 1 0 1 1 means: 1*256 + 1*128 + 0*64 + 1*32 + 1*16 + 1*8 + 0*4 + 1*2 + 1*1
or: 443 decimal.
A subset of the place values are:
Binary: 210 29 28 27 26 25 24 23 22 21 20 1024 512 256 128 64 32 16 8 4 2 1
Octal: 87 86 85 84 83 82 81 80
2097152 262144 32768 4096 512 64 8 1
Decimal: 107 106 105 104 103 102 101 100 10000000 1000000 100000 10000 1000 100 10 1
Hex: 166 165 164 163 162 161 160 16777216 1048576 65536 4096 256 16 1
Converting from Binary to Octal:
Because each octal digit can be represented by exactly 3 binary digits, all you need do is mechanically divide the binary number into groups of 3 digits, starting from the right. Then write the octal equivalent under each set of three numbers.
For example, given the following, simple, binary number
110101010101100010111110101010110
it becomes:
binary: 110 101 010 101 100 010 111 110 101 010 110
octal: 6 5 2 5 4 2 7 6 5 2 6
Converting from Binary to Hexadecimal:
Because each hex digit can be represented by 4 binary digits, all you need do is divide the binary number into groups of 4 digits, again starting from the right.
Then write the hexadecimal equivalent under each set of four digits.
For example, given the following binary number
111101110110101101110100100101101001001
it becomes:
(Notice that I had to add a leading zero to make 4 bits here) |
binary 0111 1011 1011 0101 1011 1010 0100 1011 0100 1001
hex 7 B B 5 B A 4 B 4 9
Converting from Octal to Binary:
This is just the reverse of the conversion from binary to octal shown above. Rewrite the octal number with some space between the digits, and then write the three digit octal representation for each digit below it. Remember that you must always use three digits. the numbers one and two must be represented by 001 and 010 respectively.
For example, given the following octal number:
2364700321
rewritten becomes: 2 3 6 7 0 0 3 2 1
in binary: 010 011 110 111 000 000 011 010 001
Converting from Hexadecimal to Binary:
This is just the reverse of the Binary to Hexadecimal conversion process shown above. Rewrite the hex number with some space between the digits, and then write the four digit hex representation for each digit below it. Remember that you must always use four digits. the numbers one and two must be represented by 0001 and 0010 respectively.
For example, the following hexadecimal number:
AF3679DD002
rewritten becomes: A F 3 7 6 9 D D 0 0 2
in binary: 1010 1111 0011 0111 0101 1001 1101 1101 0000 0000 0010
Converting from Hexadecimal to Octal, or Octal to Hexadecimal:
This too is a simple, mechanical conversion. To convert from Hexadecimal to Octal, simply rewrite the Hexadecimal number with more spaces, as we did above, then write the four digit binary representations. Divide the resulting binary number into groups of three binary digits, and write the corresponding octal number.
For example, given the following hexadecimal number:
AF36D02
rewritten: A F 3 6 D 0 2
in binary 4's: 1010 1111 0011 0101 1101 0000 0010 regroup
in binary 3's: 001 010 111 100 110 101 110 100 000 010
in octal: 1 2 7 4 6 5 6 4 0 2
So we can see that AF36D0216 is equal to 12746564028
Going the other way, starting with the octal number:
12773244
rewritten: 1 2 7 7 3 2 4 4
in binary 3's: 001 010 111 111 011 010 100 100
regroup
in binary 4's: 0010 1011 1111 0110 1010 0100
in hex: 2 B F 6 A 4
So we can see that 127732448 is equal to 2BF6A416
Converting from Hexadecimal to Decimal:
Now we need to look at a couple of mathematical conversions. Unlike the three bases we have played with above, binary, octal, and hexadecimal, the base ten numbering system does not lend itself to clean, mechanical conversions. To convert Hexadecimal to Decimal, you need to begin by multiplying each of the hexadecimal numbers by their positional values as expressed in decimal. Then you must add the resulting values to calculate the value of the number. Let's look at a decimal example first:
1254 (One thousand, two hundred and fifty four) means
multiply add up1 * 103 or 1000
+ 2 * 102 + 200
+ 5 * 101 + 50
+ 4 * 100 + 4
1254
The same is true of the other bases. (You might want to check back on page 1 for the positional translation table.)
Starting with the hexadecimal number:
A4D31
We look at the decimal value of each digit in relation to its place value:
A * 164 or 10 * 65536 655360
+ 4 * 163 + 4 * 4096 16384
+ D * 162 + 13 * 256 3328
+ 3 * 161 + 3 * 16 48
+ 1 * 160 + 1 * 1 1
675121 in decimal
Converting from Octal to Decimal:
You follow the same process converting from octal to decimal. First you multiply the digits times their place values, then you add up the resulting numbers.
Starting with the octal number:
724358
Calculate the decimal value for each digit depending on its place value:
7 * 84 or 7 * 4096 28762
2 * 83 + 2 * 512 1024
4 * 82 + 4 * 64 256
3 * 81 + 3 * 8 24
5 * 80 + 5 * 1 5
30071 in decimal
Converting from Decimal to Hexadecimal (Divide and conquer)
All we have left, is to convert from our favorite, decimal, to the other bases. This process is the reverse of the conversion to decimal, so rather than multiplying, we now divide.
The first step is to determine the largest place value number that will divide into the decimal number we are trying to convert. That will tell us how many digits we will have in our converted number. One way to do this is to find the place value that is one too big to divide into our decimal number. Then we take the next smallest place value as our initial number to divide by. For example, if we want to convert 52591 decimal into hexadecimal, we must first determine how many hexadecimal digits we will need. 164 (65536), is too big, but 163 (4096) will divide, so we know we have 4 digits in our number. (163...160).
Once we have the starting value, we simply divide our target number by the place values, and record the results. Remember to always use the correct digits for the base you are converting into. Let's do one:
Starting with 52591
1. We look at the table on page 1, and see that 164 (65536) is too large to divide into our target, but 163 (4096) will work. Therefore we know we will have 4 digits in our answer. I like to make a line for each digit.
____ ____ ____ ____
2. Now divide our target by the first positional value, this will give us our leftmost digit.
52591 / 4096 = 12 with 3439 left. That means our first digit is C (12 decimal).
So now we know the leftmost, or highest order, digit.
__C_ ____ ____ ____
3. Since we have 3439 left, and we have taken care of our leftmost positional value, we need to divide by the next position, to see how many of those are in our number.
3439 / 256 = 13 with 111 left. That means our second digit is D.
Now we know two digits.
__C_ _D__ ____ ____
4. Next we need to divide the remaining number by our next positional value, and see how many of them are in our number.
111 / 16 = 6 with 15 left. That means our third digit is 6.
__C_ __D_ __6_ ____
5. Finally, since we have 15 left, we know our rightmost digit. The positional value is 1, and any number divided by 1 is itself, so all we need to do is plug in our final digit.
__C_ __D_ __6_ __F_
6. Now our conversion is complete. The decimal number 52591 is equal to the hexadecimal number CD6F. To test our answer and make sure we are correct, we can do the conversion from hexadecimal back to decimal.
C * 163 or 12 * 4096 = 49152
D * 162 + 13 * 256 = 3328
6 * 161 + 6 * 16 = 96
F * 160 + 15 * 1 = 15
52591
So we can see that our conversion is correct.
A simple check is to count the number of digits you have in your answer. If you are converting from a smaller base, like decimal, to a larger base, like hexadecimal, you will always have fewer digits in your answer than in the number you are converting from. For example, converting from this 5 digit decimal number you end up with 4 hexadecimal digits. On the other hand, if you are converting from a larger base, like decimal, to a smaller base, like octal, you will end up with more digits in the conversion.
Converting from Decimal to Octal
This process is the same as we just saw with hexadecimal, except we will be using powers of 8 rather than powers of 16. Let's convert 84543 decimal to octal.
1. First we need to determine the number of digits. From page one we see that 86 (262144) is too large, but that 85 (32768) will work. Therefore we have 6 digits in our answer.
___ ___ ___ ___ ___ ___
2. Divide 84543 by 85 to get our first digit.
84543 / 32768 = 2 with 19007 left.
_2_ ___ ___ ___ ___ ___
3. Now divide our remainder, 19007 by 84 to get the next digit.
190007 / 4096 = 4 with 2623 left.
_2_ _4_ ___ ___ ___ ___
4. Divide 2623 by 83.
2623 / 512 = 5 with 63 left
_2_ _4_ _5_ ___ ___ ___
5. Divide 63 by 82. Hmmm. We have a little problem here. We can't divide 63 by 82 because we can't divide 64 into 63. Since we can't divide, is seems we have 0 64's in that number. Put in a zero into our number to hold the place, and keep the 63 we have left for the next step.
_2_ _4_ _5_ _0_ ___ ___
6. Divide 63 by 81.
63 / 8 = 7 with 7 left.
_2_ _4_ _5_ _0_ _7_ ___
7. Now we can just plug in the remainder as the last digit, and we have the conversion done.
_2_ _4_ _5_ _0_ _7_ _7_
8. Now we can check our answer, to make sure we are correct by converting from octal back to decimal.
2 * 85 or 2 * 32768 = 65536
+ 4 * 84 + 4 * 4096 = 16384
+ 5 * 83 + 5 * 512 = 2560
+ 0 * 82 + 0 * 64 = 0 Don't just skip this step!
+ 7 * 81 + 7 * 8 = 56
+ 7 * 80 + 7 * 1 = 7
84543
Converting from Decimal to Binary
Converting from decimal to binary follows the same process as the conversions from decimal to hexadecimal or octal. The only differences are that you will have more digits in your answer than in the number you started with, and you must use the powers of two chart to determine your leftmost digit. Let's convert 863 decimal to binary.
1. Determine the left most digit. 210 (1024) is too large, so or leftmost digit is 29 (512). That means we have 10 digits.
___ ___ ___ ___ ___ ___ ___ ___ ___ ___
2. Divide 863 by 512.
863 / 512 = 1 with 351 left.
_1_ ___ ___ ___ ___ ___ ___ ___ ___ ___
Note: Since we are building a binary number, we don't really need to divide, the biggest digit we can have is 1, so all we need to do is subtract each place value from the number we start with. Don't forget to keep track of the zeros, though!
2. Subtract 256 from 351.
351 - 256 = 95
_1_ _1_ ___ ___ ___ ___ ___ ___ ___ ___
3. Subtract 128 from 95.
95 - 128 = 0.
_1_ _1_ _0_ ___ ___ ___ ___ ___ ___ ___
4. Subtract 64 from 95.
95 - 64 = 31.
_1_ _1_ _0_ _1_ ___ ___ ___ ___ ___ ___
5. Subtract 32 from 31.
31 - 32 = 0.
_1_ _1_ _0_ _1_ _0_ ___ ___ ___ ___ ___
6. Subtract 16 from 31.
31 - 16 = 15.
_1_ _1_ _0_ _1_ _0_ _1_ ___ ___ ___ ___
7. Subtract 8 from 15.
15 - 8 = 7
_1_ _1_ _0_ _1_ _0_ _1_ _1_ ___ ___ ___
8. Subtract 4 from 7.
7 - 4 = 3.
_1_ _1_ _0_ _1_ _0_ _1_ _1_ _1_ ___ ___
9. Subtract 2 from 3.
3 - 2 = 1.
_1_ _1_ _0_ _1_ _0_ _1_ _1_ _1_ _1_ ___
10. Place the final digit.
_1_ _1_ _0_ _1_ _0_ _1_ _1_ _1_ _1_ _1_
11. Convert from binary back to decimal to check our work:
1 * 29 or 1 * 512 = 512
+ 1 * 28 1 * 256 = 256
+ 0 * 27 0 * 128 = 0
+ 1 * 26 1 * 64 = 64
+ 0 * 25 0 * 32 = 0
+ 1 * 24 1 * 16 = 16
+ 1 * 23 1 * 8 = 8
+ 1 * 22 1 * 4 = 4
+ 1 * 21 1 * 2 = 2
+ 1 * 20 1 * 1 = 1
863
Now you can convert any of the 4 common bases from one to another. I realize there are whiz-bang calculators that can do this for you, but it is important for you to be able to do this conversion by hand, so you understand the relationships among the bases.
If you would like to take a quiz on this material, you can see just how well you actually understand base conversion and the like. The quiz also covers adding in the various bases, so you might want to experiment with that, just a bit, before you take it. Either way, have fun!