1 private static String hexString="0123456789ABCDEF"; 2 3 public static String strEncode10_16(String str10) { 4 byte[] bytes=str10.getBytes(); 5 StringBuilder sb= new StringBuilder(bytes.length * 2); 6 7 for(int i=0;i<bytes.length;i++) 8 { 9 sb.append(hexString.charAt((bytes[i]&0xf0)>>4)); 10 sb.append(hexString.charAt((bytes[i]&0x0f)>>0)); 11 } 12 return sb.toString(); 13 } 14 15 public static String strDecode16_10(String str16) { 16 17 ByteArrayOutputStream baos=new ByteArrayOutputStream(str16.length()/2); 18 19 for(int i=0;i<str16.length();i+=2) 20 baos.write((hexString.indexOf(str16.charAt(i)) << 4 | hexString.indexOf(str16.charAt(i+1)))); 21 return new String(baos.toByteArray()); 22 }