Strumenti Utente

Strumenti Sito


javabase62

Global vars:

final String charSequence = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
final int base = 62;

Encode:

long time = (new Date()).getTime();
String ans = "";
int res = 0;
while (time != 0 && ans.length() <= 8)
{
	res = (int) (time % base);
	time /= base;
	ans = charSequence.charAt(res) + ans;
}

Decode:

long ans = 0L;
char[] chars = encodedString.toCharArray();
final int len = chars.length - 1;
for (int idc = len; idc >= 0; idc--)
{
	int pos = charSequence.indexOf(chars[idc]);
	ans += pos * Math.pow(base, len - idc);
}
 
Date date = new Date(ans);
javabase62.txt · Ultima modifica: 2017/05/03 15:48 (modifica esterna)