首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

变换数字的进制

2012-12-22 
转换数字的进制/** ** 转换数字的进制 */public class EnterSystem {public static void main(String args

转换数字的进制

/** *  * 转换数字的进制 */public class EnterSystem {public static void main(String args[]){//八进制数字的声明,在前面加上0int iOct = 0567;//十进制数字的声明int iTen = 1000;//十六进制数字的声明,在前面加上0x,x不区分大小写int iHex = 0xABCD;System.out.print("八进制0567转换成二进制:");System.out.print(Integer.toString(iOct,2) + "; ");System.out.println(Integer.toBinaryString(iOct));//八进制数转换成十进制数System.out.print("八进制0567转换成十进制:");System.out.print(Integer.toString(iOct,10) + "; ");System.out.println(Integer.toString(iOct));//八进制数转换成十六进行数System.out.print("八进制0567转换成十六进制:");System.out.print(Integer.toString(iOct,16) + "; ");System.out.println(Integer.toHexString(iOct));//还可以转换成其他进制System.out.print("八进制0567转换成七进制:");System.out.println(Integer.toString(iOct,7));//同样可以将十进制、十六进制数转换成其他任意进制的数字System.out.print("十进制1000转换成十六进制:");System.out.print(Integer.toString(iTen,16) + "; ");System.out.println(Integer.toHexString(iTen));System.out.print("十进制1000转换成八进制:");System.out.println(Integer.toOctalString(iTen));System.out.print("十六进制0xABCD转换成十进制:");System.out.println(Integer.toString(iHex,10));System.out.print("十六进制0xABCD转换成二进制:");System.out.print(Integer.toBinaryString(iHex) + "; ");System.out.println(Long.toBinaryString(iHex));}}

热点排行