static String toHex(int n) { int i; Stack<String> st = new Stack<String>(); Map<Integer, String> map = new HashMap<>(); for (int j = 0; j<10; j++) { map.put(j, j+""); } map.put(10, "A"); map.put(11, "B"); map.put(12, "C"); map.put(13, "D"); map.put(14, "E"); map.put(15, "F"); do { i = n%16; st.push(map.get(i)); n = n / 16; } while (n != 0); String result = ""; do { result = result.concat(st.pop()); } while (!st.empty()); return result;}
Sign in to make a reply
jasmine