private static char[] charSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".toCharArray();
/** * 将10进制转化为62进制 * * @param number 将要转换的10进制数字 * @param length 转化成的62进制长度,不足length长度的话高位补0,否则不改变什么 * @return */ public static String convert10To62(long number, int length) { Long rest = number; Stack<Character> stack = new Stack<Character>(); StringBuilder result = new StringBuilder(0); while (rest != 0) { stack.add(charSet[new Long((rest - (rest / 62) * 62)).intValue()]); rest = rest / 62; } for (; !stack.isEmpty(); ) { result.append(stack.pop()); } int result_length = result.length(); StringBuilder temp0 = new StringBuilder(); for (int i = 0; i < length - result_length; i++) { temp0.append('0'); } return temp0.toString() + result.toString(); }