Computer Science Canada Number Conversion help |
Author: | Klick [ Thu May 18, 2006 5:57 pm ] | ||
Post subject: | Number Conversion help | ||
As a part of my ecryption program for class, I would 5 numbers to be put into 1 large number, by the following sequence: 8,24,7,0,3 Large Number = 8 * (27**4) + 24 * (27**3) + 7 * (27**2) + 0 * (27**1) + 3 * (27 **0) The number in this case would be 4729026. Converting the 5 numbers into 1 number was fairly simple to figure out on my own. I need help recovering numbers from that large number. I figure that i can do this using mod by the series of powers of 27, and then subtract the remainder from the total Like so:
It works for the last 2 numbers for some, reason, but fails miserably on the first 3. The problem I think, is the way I am approching the solution, or I am missing something important. Any suggestions or help will be greatly appreciated. Much Thanks! |
Author: | TheOneTrueGod [ Thu May 18, 2006 6:27 pm ] | ||||
Post subject: | |||||
Yarr, sorry for doing it entirely for you, its generally against my policy to do that, but I couldn't get this one after half a second of looking at it, so I tinkered with it till I got it ![]() I will now attempt to explain where you went wrong.
The above is your code. Lets pick an arbitrary letter to represent what the first number is. I like n, so lets go with that. If we divide the "largenum" by 27**4, the resulting number will be between n * 27**4 and (n+1)*27**4. Therefore, if we truncate that number, we will get what n is. Now, just subtract n * 27**4 from the large number and repeat. One other error you made in yours is "power" started at 1, when it should have started at zero (look at the largenum calculation). |
Author: | Klick [ Thu May 18, 2006 6:37 pm ] |
Post subject: | |
You really are TheOneTrueGod!! I knew i was missing something in it, just couldn't figure it out. Thanks a bunch. This will really help me out alot. Thanks again! |