/** * * <p> * Description:将十进制数转成任何指定的进制数 * <p> * <p> * Copyright:copyright (c) 2013 * <p> * <p> * Create Date:2013-12-21 * <p> * <p> * Company:ShangHai University * <p> * * @author WANGXU * @versionv1.1 */ public class DecimalToOtherBases { /** * * @param num * 需要转换进制的数字 * @param base * 需要转成几进制 * @return 转换结果 */ 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(500, 4)); } }
时间: 2024-10-14 21:04:21