public class Shiliu{
public static void toHex(int a)
{StringBuffer sb=new StringBuffer();
for(;a>0;a=a>>>4)
{
int x=a&15;
if(x>9)
sb.append((char)(x-10+'A'));
if(x<=9)
sb.append(x);
}
System.out.println(sb.reverse());
}
public static void main(String[] args){
int n=2560;
toHex(n);
}
}
这样可以
public class Shiliu{
public static void toHex(int a)
{StringBuffer sb=new StringBuffer();
int y;
for(;a>0;a=a>>>4)
{
int x=a&15;
if(x>9)
y=(char)(x-10+'A');
sb.append(y);
if(x<=9)
sb.append(x);
}
System.out.println(sb.reverse());
}
public static void main(String[] args){
int n=2560;
toHex(n);
}
}
为什么这样不可以?
|