2016年6月20日 星期一

Integer, Long類別方法

Integer, Long類別提供三個類別方法做進位別的轉換
(1)toBinaryString(十進位整數)
(2)toOctalString(十進位整數)
(3)toHexString(十進位整數)


public class HexOctBinary
{
public static void main(String args[])
{
int x=123;

System.out.println("十進位:" + x);
System.out.println("十六進位:0x"+Integer.toHexString(x));
System.out.println("八進位:0" + Integer.toOctalString(x));
System.out.println("二進位:0b" + Integer.toBinaryString(x));
}
} 

沒有留言:

張貼留言