public static void toBinary(int num){
trans(num,1,1);
}
public static void toHex(int num){
trans(num,15,4);
}
public static void toOctal(int num){
trans(num,7,3);
}
public static void trans(int num,int base,int offset){
if(num==0){
System.out.println('0');
return;
}
char[] chs={'0','1','2','3',
'4','5','6','7',
'8','9','A','B',
'C','D','E','F'};
char[] ch = new char[32];
int pos=ch.length;
while(num!=0){ int temp = num & base;
ch[--pos] = chs[temp];
num = num >>> offset;
}
//System.out.println("pos="+pos);
for(int x=pos;x<ch.length;x++){
System.out.print(ch[x]);
}
System.out.println();
}