Skip to content

Instantly share code, notes, and snippets.

@engleek
Created February 9, 2010 23:14
Show Gist options
  • Save engleek/299808 to your computer and use it in GitHub Desktop.
Save engleek/299808 to your computer and use it in GitHub Desktop.
Base 62 String Decode
byte[] strValDecode(String s)
{
final String alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
BigInteger b = BigInteger.ZERO;
BigInteger b62 = new BigInteger("62");
for (int i=0; i<s.length(); i++) {
int idx = alphabet.indexOf(s.codePointAt(i));
b = b.multiply(b62).add(new BigInteger(Integer.toString(idx)));
}
return b.toByteArray();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment