import java.util.*;public class MainTest { public static void main(String[] args) { String hex = toHex(12500); if (hex.equalsIgnoreCase("30D4")) { System.out.println("测试通过"); } else { System.out.println("测试失败"); } } static String toHex(int n) { String res = ""; Deque<String> deque = new LinkedList<>(); List<String> hdict = List.of("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"); int nl = 0; while (n != 0) { nl = n & 0xF; n = n >> 4; deque.push(hdict.get(nl)); } String res1 = ""; try { while ((res1 = deque.pop()) != null) { res = res + res1; } } catch (NoSuchElementException e) { } return res; }}
Sign in to make a reply
roc_cn