So I have to take my AP computer science test next week and I know for a fact that base conversions will be on it. Can anyone explain how to do these, both from a higher base to a lower base and from a lower base to a higher base? On paper I mean.
But this is just a calculator. And that little piece of info at the bottom didn't help much. I need to know how to do it by hand, and I did try searching, I couldn't find any sites that explain it simply enough for me to understand. That's why I was hoping someone here may know. :C
And thanks, I'll try my best, even though I'm not too confident that I'll get a high grade. ^___^;;
I don't undestand what you mean by base conversion. Do you mean simply turning for example 8 (in base 10) into binary? Or from binary to hexadecimal? How many different bases are you supposed to know?
From the aforementioned link, it says to convert the decimal (base 10) number 640,000 to base 60, it is: 2 x 60^3 + 57 x 60^2 + 46 x 60^1 + 40 x 60^0 = 640,000
therefore the base 60 number is 2,57,46,40 (numerals separated by commas)
As another example, from 753 (base 8) to base 4:
1) convert 753 (base 8) to base 10 7 x 8^2 + 5 x 8^1 + 3 x 8^0 7*64 + 5*8 + 3*1 = 491 (base 10)
2) convert that to base 4 1*4^4 + 3*4^3 + 2*4^2 + 2*4^1 + 3*4^0 = 491 (base 10)
so, 491 (base 10) = 13223 (base 4)
Always maximize the coefficients of the higher exponents (without going over);
i.e. 1*4^4 + 3*4^3 + 2*4^2 + 2*4^1 + 3*4^0
It is incorrect to have 1*4^2 because that would cause an overflow in the coefficients of lower powers.
Clear?
Last edited by reci; 05-04-2012 at 04:52 PM.
Reason: formatted text for clarity
Reci's answer is great. I'll explain it in a slightly different more tedious but less difficult way if it helps.
First convert to base 10. This is easy, and it's clear how to do it from looking at reci's (1).
Then, convert that result to the base you need.
Ex: Base-2 is the easiest. Make a simple table like this, with 2's and their powers on the left, and the base 10 versions (which you should have memorized) on the right:
Look for the highest number in the right column of the table that is lower than 357.
That number is 256. To the left of 256 is 2^8, so write 1 * 2^8.
Now subtract 256 from 357 to get 101.
Repeat those steps with 101 instead of 357:
Spoiler for Same steps with 101:
Look for the highest number in the right column that is lower than 101.
That number is 64. To the left of 64 is 2^6, so write 1 * 2^6. (Now you have 1 * 2^8 + 1 * 2^6).
Now subtract 64 from 101 to get 37.
Keep repeating until you get to 0, then add all the numbers. The result should be 1 * 2^8 + 1 * 2^6 + 1 * 2^5 + 1 * 2^2 + 1 * 2^0.
Now, starting from the left, write the coefficient of 2^8: 1
Then keep going down with the exponents. Since there is no 2^7, an invisible 0 * 2^7 is implied, so add a 0: 10
Then go down to 2^6. Since there is one 2^6, add another 1: 101
Spoiler for The rest, same steps:
There is one 2^5: 1011
There are no 2^4's: 10110
There are no 2^3's: 101100
There is one 2^2: 1011001
There are no 2^1's: 10110010
There is one 2^0: 101100101 (your answer)
To convert base-10 to any other base, make another table.
For example, with base 4, this would be the table:
As before, find the highest number in the right column that is lower than 1273. That number is 1024, so you need to write 4^5.
Now, this step is different from the binary table.
Count how many times 1024 can be multiplied before going over 1273. This number is your coefficient for the current term. In this case, it is 1, so you have 1 * 4^5.
That is the only difference in every step. The rest is similar to the above base-2 example.
Spoiler for The rest:
Subtract 1024 from 1273 to get 249.
The highest number in the table that is lower than 249 is 64, which is 4^3.
How many times can 64 be multiplied without going over 249? 3 times, so your coefficient is 3. You now have 1 * 4^5 + 3 * 4^3.
Subtract 3 * 4^3 from 249 to get 57.
The highest number on the table that is lower than 57 is 16, which is 4^2.
How many times can 16 be multiplied without going over 57? 3 times, so your coefficient is 3. You now have 1 * 4^5 + 3 * 4^3 + 3 * 4^2.
Subtract 3 * 4^2 from 57 to get 9.
The highest number on the table lower than 9 is 4, which is 4^1.
4^1 can be multiplied 2 times before going over 9, so your coefficient is 2. You now have 1 * 4^5 + 3 * 4^3 + 3 * 4^2 + 2 * 4^1.
Subtract 2 * 4^1 from 9 to get 1.
The highest number on the table lower than or equal to 1 is 1, or 4^0, so the coefficient is 4^0. The result is 1 * 4^5 + 3 * 4^3 + 3 * 4^2 + 2 * 4^1 + 1 * 4^0.
Now, write the coefficients, as before, starting on the left:
There is 1 4^5, so write 1.
There are 0 4^4's, so add a 0: 10
There are 3 4^3's, so add a 3: 103
There are 3 4^2's, so add a 3: 1033
There are 2 4^1's, so add a 2: 10321
There is one 4^0, so add a 1: 103321 (your answer)
@Reci, yes, I can read, but I needed it to be explained much more simply. Obviously I didn't understand it when I read it, and needed a step by step explanation, which Dianeva was kind enough to type out for me. Thank you very much for that, Dianeva.
Reci, looking at your explanation now, I see that it makes sense, and I appreciate you writing it up for me. I'll do some practice problems and hopefully get those questions right on the test. Thanks, both of you.
Conversions among binary, base-10 and hex might make sense in CS. Maybe they just want to make sure you understand the concept of bases. Base-3 computers might be in the future and are supposed to work more efficiently in theory. Making everyone memorize it all still seems to be overdoing it to me though.
I saw CS on the AP schedule and just lol'ed. My school has one CS-related course, which was cancelled this year because not enough people signed up.
Best of luck though. Know that I can commiserate - I have Spanish tomorrow, and it shall indeed totally suck . My hopes for statistics are somewhat higher, though.
Don't forget to study your binary vectors (and translations, or any n-ary vector system), which is fundamental to many modern applications, computer languages, and other sciences.
Bookmarks