public class DtoH {
public static void main(String[] args) {
toHex(60);
}
public static void toHex(int num) {
for(int x=0; x<8; x++) {
int temp = num & 15;
if(temp>9)
System.out.println((char)(temp-10+'A')); //????
else
System.out.println(temp);
num = num >>> 4;
}
}
}以上是一个十进制转换十六进制的小程序,把60这个十进制数转换成十六进制。
其中temp-10+'A'这段代码是什么意思呢?
我知道输出是十六进制的'C',但是想问下这个代码涉及到什么知识点?
难道10在十六进制是‘A’,2+'A'就等于'C'了?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货