十进制与二八十六进制之间转换方法:
public static void trans(int num,int base,int offset){
if(num ==0){
return;
}
char[] chs = {'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] = chs[temp];
num = num>>>offset;
}
for(int i=pos;i<arr.length;i++){
System.out.println(arr[i]);
}
}
方法中的
while(num!=0){
int temp = num&base;
arr[--pos] = chs[temp];
num = num>>>offset;
}
这段代码什么意思?没看懂?好心人解释下啊? |