/*
* 进制的转换
* 需求:十进制-->二进制
* 十进制-->八进制
* 十进制-->十六进制
* 思路: 查表法
*
* */
import java.util.Scanner;
public class youhua {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int jinzhi = in.nextInt(); //十进制转几进制
int num = in.nextInt(); //要转的数
switch(jinzhi){
case 2:
toBin(num);
break;
case 8:
toBa(num);
break;
case 16:
toHex(num);
break;
default:
System.out.println("error!");
}
}
//十进制-->二进制
public static void toBin(int num){
trans(num, 1, 1);
}
//十进制-->八进制
public static void toBa(int num){
trans(num, 7, 3);
}
//十进制-->十六进制
public static void toHex(int num){
trans(num, 15, 4);
}
public static void trans(int num, int base, int offset){
char[] chs = {'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9', 'A', 'B',
'C', 'D', 'E', 'F'};
char[] arr = new char[8];
int pos = arr.length;
int temp;
while(num != 0){
temp = num&base; //取低几位
arr[--pos] = chs[temp]; // 存入数组
num = num>>>offset; //除以进制数
}
for(int i=pos; i<arr.length; i++)
System.out.print(arr[i]);
}
}