class Solution {
public String int2hex(int num) {
switch (num) {
case 0x00000000 : return "0";
case 0x10000000 : return "1";
case 0x20000000 : return "2";
case 0x30000000 : return "3";
case 0x40000000 : return "4";
case 0x50000000 : return "5";
case 0x60000000 : return "6";
case 0x70000000 : return "7";
case 0x80000000 : return "8";
case 0x90000000 : return "9";
case 0xa0000000 : return "a";
case 0xb0000000 : return "b";
case 0xc0000000 : return "c";
case 0xd0000000 : return "d";
case 0xe0000000 : return "e";
case 0xf0000000 : return "f";
}
return "";
}
public String toHex(int num) {
if (num == 0) return "0";
boolean flag = false;
String ans = "";
for (int i = 0; i < 8; i++) {
int and = num & 0xf0000000;
if (and != 0) flag = true;
if (flag) ans += int2hex(num & and);
num <<= 4;
}
return ans;
}
}