public class MyToHex {
public static void main (String [] args ){
int num = 368;
String x = getHex(num);
System.out.println(x);
}
public static String getHex(int num){
char [] chs={'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
int count = 0;
StringBuilder sb = new StringBuilder();
while (num!=0){
int temp = num%16;
sb.append(chs[temp]);
count++;
num = num>>>4;
}
int i = 32-count;
while(i>0){
sb.append(0);
i--;
}
return sb.reverse().toString();
}
} |
|