I am attempting to come up with a better method for doing this:
public static String longToPlayerName(long name) {
int i = 0;
char[] nameCharacters = new char[12];
while (name != 0L) {
long ll = name;
name /= 37L;
nameCharacters[11 - i++] = playerNameXlateTable[(int) (ll - (name * 37L))];
}
return new String(nameCharacters, 12 - i, i);
}
public static long playerNameToInt64(String s) {
long l = 0L;
for (int i = 0; (i < s.length()) && (i < 12); i++) {
final char c = s.charAt(i);
l *= 37L;
if ((c >= 'A') && (c <= 'Z')) {
l += (1 + c) - 65;
} else if ((c >= 'a') && (c <= 'z')) {
l += (1 + c) - 97;
} else if ((c >= '0') && (c <= '9')) {
l += (27 + c) - 48;
}
}
while (((l % 37L) == 0L) && (l != 0L)) {
l /= 37L;
}
return l;
}
I can't seem to come up with a better way. Any ideas would be excellent!