標題:
Java 進位制轉換
[打印本頁]
作者:
tonyh
時間:
2020-12-31 20:27
標題:
Java 進位制轉換
[attach]11182[/attach]
//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("-------------------------");
}
}
複製代碼
作者:
黃宇瑄
時間:
2021-1-4 20:06
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Ch01 {
Ch01() throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
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("-------------------------");
}
public static void main(String[] args) throws IOException {
new Ch01();
}
}
複製代碼
作者:
黃宇綸
時間:
2021-1-4 20:16
public class Ch01 {
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("-------------------------");
}
}
複製代碼
作者:
李沛昂
時間:
2021-1-11 18:30
public class Ch00 {
public static void main(String[] args) {
int i=12345;
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("11000000111001", 2));
System.out.println("二進位轉十進位"+Integer.valueOf("30071", 8));
System.out.println("二進位轉十進位"+Integer.valueOf("3039", 16));
System.out.println("----------------------------");
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2