標題:
Java 進位制轉換
[打印本頁]
作者:
tonyh
時間:
2023-4-21 19:30
標題:
Java 進位制轉換
//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("-------------------------");
}
}
複製代碼
作者:
陳宥穎
時間:
2023-4-21 20:02
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("6c",16));
System.out.println("-------------------------");
}
}
複製代碼
作者:
林祐霆
時間:
2023-4-21 20:08
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TLE {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
TLE() throws Exception {
int e=678;
System.out.println("-------------------------");
System.out.println("10 --> 2: "+Integer.toBinaryString(e));
System.out.println("10 --> 8: "+Integer.toOctalString(e));
System.out.println("10 --> 16: "+Integer.toHexString(e));
System.out.println("-------------------------");
System.out.println("2 --> 10: "+Integer.valueOf(Integer.toBinaryString(e),2));
System.out.println("8 --> 10: "+Integer.valueOf(Integer.toOctalString(e),8));
System.out.println("16 --> 10: "+Integer.valueOf(Integer.toHexString(e),16));
System.out.println("-------------------------");
}
public static void main(String[] args) throws Exception {
new TLE();
}
}
複製代碼
作者:
洪承廷
時間:
2023-4-21 20:10
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class AAA {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str;
int i=108;
AAA() throws IOException
{
System.out.println(Integer.toBinaryString(Integer.parseInt(str)));
System.out.println("-------------------------");
System.out.println("10->2"+Integer.toBinaryString(i));
System.out.println("10->8"+Integer.toOctalString(i));
System.out.println("10->16"+Integer.toHexString(i));
System.out.println("-------------------------");
System.out.println("10->2"+Integer.valueOf("1101100", 2));
System.out.println("10->8"+Integer.valueOf("154", 8));
System.out.println("10->16"+Integer.valueOf("6c", 16));
}
}
public static void main(String[] args) throws IOException {
new AAA();
}
}
複製代碼
作者:
李穎俊
時間:
2023-4-21 20:11
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class P1 {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
P1() throws Exception{
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 Exception{
new P1();
}
}
複製代碼
作者:
董宸佑
時間:
2023-4-21 20:23
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("-------------------------");
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://istak.org.tw/seed/)
Powered by Discuz! 7.2