首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

java基础 ——十六进制的变换一

2012-10-11 
java基础 ——十六进制的转换一class ToHex {public static void main(String[] args) {toHex1(60)}public

java基础 ——十六进制的转换一
class ToHex
{
public static void main(String[] args)
{
toHex1(60);
}
public static void toHex1(int num){
StringBuffer sb= new StringBuffer();
for(int x=0;x<8;x++){
int temp=num&15;
if(temp>9){
//System.out.println((char)(temp-10+'A'));
sb.append((char)(temp-10+'A'));
}else{
//System.out.println(temp);
sb.append(temp);
}
num = num>>>4;
}
System.out.println(sb.reverse());
}
}

热点排行