public class ArrayTest2 {
public static void main(String[] args) {
int toHexNum=100;
toHex_2(toHexNum);
}
public static void toHex_2(int num) {
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[] arr=new char[8];
int pos = arr.length;
while(num!=0){
int temp=num&15;
arr[--pos]=chs[temp];
num=num>>>4;
}
System.out.println("pos="+pos);
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]);
}
}
}
给你个方法,直接转。。。 |