From 49fe5bf95bfb354acd6467b5b528f6b7a63a6122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=99=A8=E9=9B=BE=E7=B9=81=E6=98=9F?= <484502012@qq.com> Date: Thu, 10 Oct 2024 15:10:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E4=BB=BB=E6=84=8F=E8=BF=9B=E5=88=B6?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E8=BD=AC=E6=8D=A2=E4=B8=BA=E5=8F=A6=E4=B8=80?= =?UTF-8?q?=E4=B8=AA=E4=BB=BB=E6=84=8F=E8=BF=9B=E5=88=B6=E7=9A=84=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BaseConverter.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/BaseConverter.java b/BaseConverter.java index 98e139d..efb63bf 100644 --- a/BaseConverter.java +++ b/BaseConverter.java @@ -43,5 +43,16 @@ public class BaseConverter { 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); + } } \ No newline at end of file