| Smac89 (201) | |
|
Hello guys, I was wondering if there is a standard for converting something like this: HELLO 27 to ?3 If someone knows how, please explain. Thanks! | |
|
|
|
| L B (3816) | |
|
This is in Java, but you can still get the basic logic from it: https://gist.github.com/LB--/4591371 (It doesn't do decimal places yet) It's annoying to explain in words. | |
|
|
|
| Smac89 (201) | |
| Thanks for that L B, but I was actually looking for a manual method of converting it. I sort of understand how it is done by machine code, but how would one convert that using pencil and paper? | |
|
|
|
| L B (3816) | ||
|
OK. Base 10 is the Decimal system, which we use. Take the number 123.45610 - it can also be written as: 100 + 20 + 3 + .4 + .05 + .006 This is called 'expanded form' and is taught to kids before 1st grade in elementary school. The reason it is called base 10 is because there are 10 digits, 0-9. You can rewrite the expanded form as powers of 10: 1*102 + 2*101 + 3*100 + 4*10-1 + 5*10-2 + 6*10-3 This is how all numbers are represented. Similarly, Binary is base 2, because it has 2 digits, 0 to 1. You can quite easily convert from base n to base m by taking advantage of dividing and taking the remainder. Let's look at 10010 and convert it to binary, for example:
This process works for any base to any other base, so long as you know how to divide and take remainder of the base you're working with. There is a convention for the digits above 9 in bases above 10. This is all the digits in base 62: 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0-9, A-Z, a-z | ||
|
Last edited on
|
||
| Smac89 (201) | |
|
Here is what I did: Convert to base 10 by getting the base 10 equivalent of the letters. So HELLO27 = 17 14 21 21 2410? I don't know if it is possible to do that so correct me if I'm wrong. Then using the numbers in base 10, I convert to base 3 using your method and I got: 122 112 210 210 2203. Is this right? | |
|
|
|
| L B (3816) | |
| Completely wrong, reread my post. | |
|
|
|