publicclassMain{publicstaticvoidmain(String[] args){int x =0x1f;// 十六进制System.out.println(x);// output: 31
x =0x1F;System.out.println(x);// output: 31
x =070;// 八进制System.out.println(x);// output: 56long y =0x1f;System.out.println(y);// output: 31
y =0x1F;System.out.println(y);// output: 31
y =070;System.out.println(y);// output: 56}}
进制转换
二进制与十进制相互转换
publicclassMain{publicstaticvoidmain(String[] args){String str =Long.toBinaryString(7);System.out.println(str);// output: 111long x =Long.parseLong("111",2);System.out.println(x);// output: 7}}
八进制与十进制相互转换
publicclassMain{publicstaticvoidmain(String[] args){String str =Long.toOctalString(63);System.out.println(str);// output: 77long x =Long.parseLong("77",8);System.out.println(x);// output: 31}}
十六进制与十进制相互转换
publicclassMain{publicstaticvoidmain(String[] args){String str =Long.toHexString(15);System.out.println(str);// output: flong x =Long.parseLong("1F",16);System.out.println(x);// output: 31}}