Java程序:
public class Main {
public static void main(String[] args) {
int num = 1234;
System.out.println("十进制:" + num);
System.out.println("二进制:" + Integer.toBinaryString(num));
System.out.println("八进制:" + Integer.toOctalString(num));
System.out.println("十六进制:" + Integer.toHexString(num));
System.out.println();
String str = "10011010010";
System.out.printf("二进制:%s\t十进制:%d\n", str, Integer.parseInt(str, 2));
str = "2322";
System.out.printf("八进制:%s\t\t十进制:%d\n", str, Integer.parseInt(str, 8));
str = "4D2";
System.out.printf("十六进制:%s\t\t十进制:%d\n", str, Integer.parseInt(str, 16));
}
}
运行测试:
十进制:1234
二进制:10011010010
八进制:2322
十六进制:4d2
二进制:10011010010 十进制:1234
八进制:2322 十进制:1234
十六进制:4D2 十进制:1234