¶ÔÓÚ10½øÖÆÊýת»»ÎªN£¨2-36£©½øÖÆÒ»°ã¶¼ÊÇÑ¡ÔñÈ¡Óà³ýµÄËã·¨½øÐÐת»» £¬ÏÂÃæ¸ø³öÁ½ÖÖ·½°¸
Ò»ÖÖÊǵݹ飬һÖÖÊǵü´ú¡£Í¨¹ýЧÂÊÆÀ¼ÛÁ½ÕßÐÔÄÜ
ÆäÖеü´úµÄ·½°¸Ö±½ÓÈ¡×ÔjavaÔ´´úÂë¡£
/*
*Class NotationConvert.java
*Create Date: 2009-11-12
*Author:a276202460
*/
package com.rich.notation;
public class NotationConvert {
private static final String[] letters = { "0", "1", "2", "3", "4", "5",
"6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "i",
"g", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z" };
static final char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z' };
public static String TentoN(int value, int number) {
if (number <= 1 || number > letters.length) {
throw new RuntimeException("Faild");
}
if (value < 0) {
return "-" + TentoN(0 - value, number);
}
if (value < number) {
return letters[value];
} else {
return (TentoN(value / number, number) + letters[value % number]);
}
}
public static String TentoN1(int value, int number) {
if (number <= 1 || number > letters.length) {
throw new RuntimeException("Faild");
}
char[] rs = new char[33];
boolean flag = value < 0;
int startindex = 32;
if (!flag)
value = 0 - value;
for (; value <= -number; value /= number)
rs[startindex--] = digits[-(value % number)];
rs[startindex] = digits[-value];
if (flag) {
rs[--startindex] = '-';
}
return new String(rs, startindex, 33 - startindex);
}
public static void main(String[] s) {
long starttime = System.currentTimeMillis();
for (int i = 0; i < 100000; i++)
TentoN(-33, 2);
System.out.println((System.currentTimeMillis() - starttime));
starttime = System.currentTimeMillis();
for (int i = 0; i < 100000; i++)
TentoN1(-33, 2);
System