- //Java 二進制,八進制,十進制,十六進制轉換
- public class Ch02 {
- public static void main( String[] args ) {
- int i=108;
- System.out.println("-------------------------");
- System.out.println("十進制轉二進制:" + Integer.toBinaryString(i));
- System.out.println("十進制轉八進制:" + Integer.toOctalString(i));
- System.out.println("十進制轉十六進制:" + Integer.toHexString(i));
- System.out.println("-------------------------");
- System.out.println("二進制轉十進制:" + Integer.valueOf("1101100", 2));
- System.out.println("八進制轉十進制:" + Integer.valueOf("154", 8));
- System.out.println("十六進制轉十進制:" + Integer.valueOf("6c", 16));
- System.out.println("-------------------------");
- }
- }
複製代碼 |