Published 2021. 6. 6. 20:16
10진수 -> 2진수, 8진수, 16진수
int i = 127;
 
String binaryString = Integer.toBinaryString(i); //2진수
String octalString = Integer.toOctalString(i);   //8진수
String hexString = Integer.toHexString(i);       //16진수

 

2진수, 8진수, 16진수 -> 10진수
import java.io.IOException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        String a = scan.next();
        
        //뒤에숫자가 8진수로 넘어오면 8, 2진수로 넘어오면 2, 16진수로 넘어오면 16 
        System.out.println(Integer.parseInt(a, 8));
    }
}
복사했습니다!