java小程序,谁能帮我解释下 以下程序代码 用文字走一遍 谢谢,本人菜鸟一枚。真的很需要详细的解释
/*去0版十进制-->十六进制**/publicclassHexadecimalconversion_1{publicstaticvoidmain(String[]arg...
/*去0版 十进制-->十六进制
*
*/
public class Hexadecimalconversion_1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int num = 60;
String s = toHex(num);
System.out.println(s);
}
public static String toHex(int num){
char[] chs = new char[8];
int index =chs.length;
while(num!=0){
int temp = num & 15;
if(temp>9)
chs[--index]=((char)(temp-10+'A'));
else
chs[--index]=((char)(temp+'0'));
num = num >>> 4;
}
return "0x"+toString(chs,index);
}
public static String toString(char[] chs,int index){
String temp = "";
for(int x=index;x<chs.length;x++){
temp=temp+chs[x];
}
return temp;
}
} 展开
*
*/
public class Hexadecimalconversion_1 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int num = 60;
String s = toHex(num);
System.out.println(s);
}
public static String toHex(int num){
char[] chs = new char[8];
int index =chs.length;
while(num!=0){
int temp = num & 15;
if(temp>9)
chs[--index]=((char)(temp-10+'A'));
else
chs[--index]=((char)(temp+'0'));
num = num >>> 4;
}
return "0x"+toString(chs,index);
}
public static String toString(char[] chs,int index){
String temp = "";
for(int x=index;x<chs.length;x++){
temp=temp+chs[x];
}
return temp;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询