| 01-23-2004, 10:38 PM | #1 |
I have discovered perhaps the simplest way to convert from base 10 to any base of your choice. Notice that this will only work for whole numbers. Of course, who needs it for anything else? I don't know how many people found a way to do it THIS easy, because all the other ways I've seen are so complicated. And, with this, you can do it in GUI. You would probably use this in a save code for an RPG (as I am doing to save a heroes levels.) Also, please notice that this specific trigger does not work for numbers larger than FF (in base 16). If you need, you can do further division and find out any number you want in any base. First create an array which is sized one less than whatever base you want to use. For this example I used base 16, so I made a little trigger to hold the contents of the specific values of numbers. THE TRIGGERS Setup Base 16 Array Events Map initialization Conditions Actions Set Base16[0] = 0 Set Base16[1] = 1 Set Base16[2] = 2 Set Base16[3] = 3 Set Base16[4] = 4 Set Base16[5] = 5 Set Base16[6] = 6 Set Base16[7] = 7 Set Base16[8] = 8 Set Base16[9] = 9 Set Base16[10] = A Set Base16[11] = B Set Base16[12] = C Set Base16[13] = D Set Base16[14] = E Set Base16[15] = F Easy so far, right? It gets easier. Now, to convert from base 10, it's as simple as this. Let X = the number you wish to convert. Set YourNewBase16Number = (Base16[(X / 16)] + Base16[(X mod 16)]) NOTICE: IT IS NOT ADDING! IT IS CONCATENATING TWO STRINGS! Make sure you don't add them. Also, the division is INTEGER divison, not regular floating point division. WHY IT WORKS First off, we have all our base 16 numbers in an array, where each index equals the character it holds. When you integer divide any number by a base you'll get the tens. Modulus the number again, and you get the leftovers - your ones. The array serves as a kind of "conversion chart." Feel free to comment or improve upon my trigger. I know it doesn't work for larger numbers, but it serves its purpose for me and will work just fine provided that your numbers don't exceed 255 using hex. EDIT: Damn, just realized this was the wrong forum. |
| 01-23-2004, 11:20 PM | #2 |
you do realize that war3 has inline conversion from base16 to base10 with prefacing your number by 0x? 0x100=256 0xFF=255 |
| 01-24-2004, 07:00 AM | #3 |
Just curious, what kind of map do you have that causes you to do this? |
| 01-24-2004, 12:31 PM | #4 |
Okay I'm lost, what's this topic about? All I can see is you setting values in to integerarrays... |
| 01-24-2004, 02:10 PM | #5 |
Dead-Inside, basically he's talking about converting from decimal into hex with an easy system. It's most useful for when you have a large save code number and you want to compress it into a smaller string. |
