I need to convert an integer into a base64-character representation. I’m using OxA3’s answer on this thread: Quickest way to convert a base 10 number to any base in .NET?
How do I inverse this to get my original integer back, given a string?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Joel Mueller’s answer should guide you the base-64 case.
In response to the preliminary code you’ve provided in your own answer, you can definitely improve its efficiency by changing the code to accomplish what your
forloop is doing (effectively an O(N)IndexOf) to use a hash lookup (which should make it O(1)).I am basing this on the assumption that
baseCharsis a field that you initialize in your class’s constructor. If this is correct, make the following adjustment:Then in your
StringToIntmethod: