|
|
@ -43,5 +43,16 @@ public class BaseConverter {
|
|
|
|
|
|
|
|
|
|
|
|
return result.toString();
|
|
|
|
return result.toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 将任意进制的数转换为另一个任意进制的数
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param str 给定进制的字符串表示
|
|
|
|
|
|
|
|
* @param sourceBase 给定进制的基数
|
|
|
|
|
|
|
|
* @param targetBase 目标进制的基数
|
|
|
|
|
|
|
|
* @return 目标进制的字符串表示
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String convertBase(String str, int sourceBase, int targetBase) {
|
|
|
|
|
|
|
|
int decimalValue = toDecimal(str, sourceBase);
|
|
|
|
|
|
|
|
return fromDecimal(decimalValue, targetBase);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|