java 字串轉16進位制(包含漢字)
阿新 • • 發佈:2019-02-14
public static String toChineseHex(String s) { String ss = s; byte[] bt = new byte[0]; try { bt = ss.getBytes("GBK"); }catch (Exception e){ e.printStackTrace(); } String s1 = ""; for (int i = 0; i < bt.length; i++) { String tempStr = Integer.toHexString(bt[i]); if (tempStr.length() > 2) tempStr = tempStr.substring(tempStr.length() - 2); s1 = s1 + tempStr + ""; } return s1.toUpperCase(); }