¶ÔÓÚ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
JAVAµÄ¿çƽ̨µÄÌØÐÔÉîÊÜjava³ÌÐòÔ±ÃǵÄϲ°®,µ«ÕýÊÇÓÉÓÚËüΪÁËʵÏÖ¿çƽ̨µÄÄ¿µÄ,ʹµÃËüºÍ±¾µØ»úÆ÷µÄ¸÷ÖÖÄÚ²¿ÁªÏµ±äµÃºÜÉÙ,´ó´óÔ¼ÊøÁËËüµÄ¹¦ÄÜ,±ÈÈçÓëһЩӲ¼þÉ豸ͨÐÅ,ÍùÍùÒª»¨·ÑºÜ´óµÄ¾«Á¦È¥Éè¼ÆÁ÷³Ì±àд´úÂëÈ¥¹ÜÀíÉ豸¶Ë¿Ú,¶øÇÒÓÐһЩÉ豸³§ÉÌÌṩµÄÓ²¼þ½Ó¿ÚÒѾ¾¹ýÒ»¶¨µÄ·â×°ºÍ´¦Àí,²»ÄÜÖ±½ÓʹÓÃjava³ÌÐòͨ¹ý¶Ë¿Úº ......