package wzs.test2;
//打印二进制,八进制,十六进制
public class Test
{
public static void main(String[] args)
{
System.out.println("0-20二进制.");
for (int i = 0; i < 20; i++)
{
System.out.print(i + ":" + Integer.toBinaryString(i) + " ");
}
System.out.println("\n0-20八进制.");
for (int i = 0; i < 20; i++)
{
System.out.print(i + ":" + Integer.toOctalString(i) + " ");
}
System.out.println("\n0-20十六进制.");
for (int i = 0; i < 20; i++)
{
System.out.print(i + ":" + Integer.toHexString(i) + " ");
}
}
}
输出结果:
0-20二进制.
0:0 1:1 2:10 3:11 4:100 5:101 6:110 7:111 8:1000 9:1001 10:1010 11:1011 12:1100 13:1101 14:1110 15:1111 16:10000 17:10001 18:10010 19:10011
0-20八进制.
0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 8:10 9:11 10:12 11:13 12:14 13:15 14:16 15:17 16:20 17:21 18:22 19:23
0-20十六进制.
0:0 1:1 2:2 3:3 4:4 5:5 6:6 7:7 8:8 9:9 10:a 11:b 12:c 13:d 14:e 15:f 16:10 17:11 18:12 19:13