现在,我正在尝试找到一种方法,在Java中将数字从一个基数转换为另一个数字,给出一个数字,数字所在的基数,以及转换为的基数.
public static void BaseConversion(String number, int base1, int base2){
//convert the number from one base to another
}
Run Code Online (Sandbox Code Playgroud)
我找到了JavaScript的解决方案,我想知道是否可以在Java中做类似的事情:
function convertFromBaseToBase(str, fromBase, toBase){
var num = parseInt(str, fromBase); //convert from one base to another
return num.toString(toBase);
}
Run Code Online (Sandbox Code Playgroud) java ×1