将十进制数转成任何指定的进制数

/**
 * 
 * <p>
 * Description:将十进制数转成任何指定的进制数
 * <p>
 * <p>
 * Copyright:copyright (c) 2013
 * <p>
 * <p>
 * Create Date:2013-12-21
 * <p>
 * <p>
 * Company:ShangHai University
 * <p>
 * 
 * @author WANGXU
 * @version Id: Demo.java,v1.1,WANGXU Exp
 */
public class DecimalToOtherBases {
	public static String baseString(int num, int base) {
		String str = "", digit = "0123456789abcdef";
		if (num == 0) {
			return "";
		} else {
			str = baseString(num / base, base);
			return str + digit.charAt(num % base);
		}
	}

	public static void main(String[] args) {
		System.out.println(baseString(5, 4));
	}
}

你可能感兴趣的:(将十进制数转成任何指定的进制数)