class ToHex
{
public static void main(String[] args)
{
int b='0'+1;
System.out.println(b);
System.out.println(toHex(30));
System.out.println(toHex(45));
System.out.println(toHex(15));
}
public static String toHex(int n)
{
StringBuffer sb=new StringBuffer();
while (n>0)
{
int a=n%16;
if (a>10)
{
char ch=(char)('A'+a-10);
sb.append(ch);
}
else
sb.append(a);
n/=16;
}
sb.append("x0");
return sb.reverse().toString();
}
|