|
|
@ -5,7 +5,14 @@ import java.util.Scanner;
|
|
|
|
|
|
|
|
|
|
|
|
public class BaseConverter {
|
|
|
|
public class BaseConverter {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 将任意进制的数转换为另一个任意进制的数。
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param numStr 原始数值的字符串表示
|
|
|
|
|
|
|
|
* @param fromBase 原始进制
|
|
|
|
|
|
|
|
* @param toBase 目标进制
|
|
|
|
|
|
|
|
* @return 转换后的字符串表示
|
|
|
|
|
|
|
|
*/
|
|
|
|
public static String convertBase(String numStr, int fromBase, int toBase) {
|
|
|
|
public static String convertBase(String numStr, int fromBase, int toBase) {
|
|
|
|
// 验证进制是否合法
|
|
|
|
// 验证进制是否合法
|
|
|
|
if (fromBase < 2 || fromBase > 16 || toBase < 2 || toBase > 16) {
|
|
|
|
if (fromBase < 2 || fromBase > 16 || toBase < 2 || toBase > 16) {
|
|
|
|