Moral Panic
Member
OK still working on my base conversion program and I have to figure out how to convert to and from up to base 35. I have the program running for when decimals are used and it works fine, but now I have to figure out how to both convert from and to special characters. (a through z)
For example, converting 42 base 10 to base 16 should return 2a and not 210.
Would anyone know how to do this without using of the likes of parseInt? (isn't allowed)
My best bet when pulling the numbers out of a string (such as "4deadc0d") is to use a scanner or loop to pull out the characters individually and find their given values. (haven't implemented it yet) But on the flipside, I'm not sure how to then convert back into the characters after getting the values out of them. Basically if think my idea might be able to convert from base 16 to base 10, but I'm unaware of how to convert from base 10 back into base 16. (basically get the values back into their letter form)
have an array or list with 1,2,3.....9 and then a....z
The way I would tackle it would be to do it the same way I do it in my head. 42 base 10 to base 16 -> 42\16 = 2 remainder 10. 2 < 16 so we find the 2nd element in our array which is 2. 10 < 16 so we find the 10th element in our array which is a.
Assume we have a bigger number than our base e.g 35550 base 10 to base 35. You so 3550 \ 35 = 101 remainder 15. 15th in array is F. 101 > 35 so we recursively call the function on 101 base 10 to base 35. That gives you 2 remainder 31. 31st in array is V. Add it to the F we got before and we have 2VF.