日期:2014-05-20 浏览次数:20858 次
public static char reHex(byte[] content, int len) { byte[] bs = new byte[len]; for (int i=0; i<len; i++) bs[i] = content[i]; String s = new String(bs); int x = Integer.parseInt(s, 16); return (char)x; } public static void main(String[] args) { //测试 byte[] bs = new byte[2]; bs[0] = '6'; bs[1] = '4'; System.out.println(reHex(bs,2)); }
------解决方案--------------------
public class Ascii2Number {
public static void main(String[] args) {
System.out.println(toAsciiHexCode( ': ') );
System.out.println(toAsciiHexCode( "toAsciiHexCode ") );
}
private static String toAsciiHexCode(String str) {
if (null == str) return " ";
StringBuilder builder = new StringBuilder();
for (int i=0; i < str.length(); i++) {
builder.append(toAsciiHexCode(str.charAt(i))).append( " ");
}
return builder.toString();
}
private static String toAsciiHexCode(char ch) {
return Integer.toHexString(48 + ch - '0 ').toUpperCase();
}
}
3A
74 6F 41 73 63 69 69 48 65 78 43 6F 64 65
------解决方案--------------------
我理解错你的意思了,其实你只是要个ASCII码而已,这个很容易实现。2楼给出的就是解决方案了。