/** * 字符串转换为16进制字符串 * * @param s * @return */ public static String stringToHexString(String s) { String str = ""; for (int i = 0; i < s.length(); i++) { int ch = (int) s.charAt(i); String s4 = Integer.toHexString(ch); str = str + s4; } return str; } /** * 16进制字符串转换为字符串 * * @param s * @return */ public static String hexStringToString(String s) { if (s == null || s.equals("")) { return null; } s = s.replace(" ", ""); byte[] baKeyword = new byte[s.length() / 2]; for (int i = 0; i < baKeyword.length; i++) { try { baKeyword[i] = (byte) (0xff & Integer.parseInt( s.substring(i * 2, i * 2 + 2), 16)); } catch (Exception e) { e.printStackTrace(); } } try { s = new String(baKeyword, "gbk"); new String(); } catch (Exception e1) { e1.printStackTrace(); } return s; }
Android 字符串和十六进制互转
最新推荐文章于 2024-03-26 17:33:37 发布