package Demo;
/*
* 将十进制转换成十六进制
*/
public class Demo14 {
public static void main(String[] args) {
int x = 60;
char[] arry = toHex(x);
toString(arry);
}
public static char[] toHex(int num) {
char[] chs = new char[8];
int index = chs.length - 1;
for (int x = 0; x < 8; x++) {
int temp = num & 15;
if (temp > 9)
chs[index] = ((char) (temp - 10 + 'A'));
else
chs[index] = ((char) (temp + '0'));
index--;
num = num >>> 4;
}
return chs;
}
public static void toString(char[] arr) {
String temp = "";
for (int x = 0; x < arr.length; x++) {
temp = temp + arr[x];
}
System.out.println("OX" + temp);
}
}
详细解释,请搜索相关教程!着只是代码!!