public class JinZhiZhuanHuan {
public static void main(String[] args){
toBin(6);
System.out.println();
toHex(60);
}
public static void toBin(int num){
trans(num,1,1);
}
public static void toO(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) {
if (num == 0){
System.out.println(0);
return;
}
char[] ch={'0','1','2','3','4','5','6','7','8','9',
'A','B','C','D','E','F'};
char[] arr=new char[32];
int pos=arr.length;
while(num!=0){
int temp=num&base;
arr[--pos]=ch[temp];
num=num>>>offset;//无符号右移
}
for(int i=pos;i<arr.length;i++){
System.out.print(arr[i]);
}
}
}