/**
* @param num
* 需要转换的数
* @param jinzhi
* 自定义进制数
* @return
*/
public int getNumber(int num, int jinzhi) throws Exception {
int temp1 = 0;//预存num的前半部分
int temp2 = 0;//预存num的后半部分
String numStr = num + "";
String jinzhiStr = jinzhi + "";
if (num < jinzhi) {
throw new Exception("自定义进制数大于要转换的数!");
}
if (num == jinzhi) {
throw new Exception("自定义进制数等于要转换的数!");
}
int length1 = (num + "").toString().length();//数据长度
int length2 = (jinzhi + "").toString().length();//自定义进制长度
temp1 = Integer.parseInt(numStr.subSequence(0, length1 - length2) + "");
temp2 = Integer.parseInt(numStr.subSequence(length1 - length2, length1)
+ "");
if (temp2 > jinzhi) {
temp1++;
}
for (int i = 0; i < length2; i++) {
temp1 = Integer.parseInt(temp1 + "0");
}
return temp1;
}
* @param num
* 需要转换的数
* @param jinzhi
* 自定义进制数
* @return
*/
public int getNumber(int num, int jinzhi) throws Exception {
int temp1 = 0;//预存num的前半部分
int temp2 = 0;//预存num的后半部分
String numStr = num + "";
String jinzhiStr = jinzhi + "";
if (num < jinzhi) {
throw new Exception("自定义进制数大于要转换的数!");
}
if (num == jinzhi) {
throw new Exception("自定义进制数等于要转换的数!");
}
int length1 = (num + "").toString().length();//数据长度
int length2 = (jinzhi + "").toString().length();//自定义进制长度
temp1 = Integer.parseInt(numStr.subSequence(0, length1 - length2) + "");
temp2 = Integer.parseInt(numStr.subSequence(length1 - length2, length1)
+ "");
if (temp2 > jinzhi) {
temp1++;
}
for (int i = 0; i < length2; i++) {
temp1 = Integer.parseInt(temp1 + "0");
}
return temp1;
}