日期:2014-05-20 浏览次数:21011 次
string str = "0xA0"; int i= str; char c = i;
------解决方案--------------------
public class TempTest { /** * @param args */ public static void main(String[] args) { String str = "0xA0"; String rtStr = bytesToHexString(str.getBytes()); System.out.println(rtStr); } /** */ /** * 把字节数组转换成16进制字符串 * * @param bArray * @return */ public static final String bytesToHexString(byte[] bArray) { StringBuffer sb = new StringBuffer(bArray.length); String sTemp; for (int i = 0; i < bArray.length; i++) { sTemp = Integer.toHexString(0xFF & bArray[i]); if (sTemp.length() < 2) sb.append(0); sb.append(sTemp.toUpperCase()); } return sb.toString(); } }
------解决方案--------------------
String s = "0xA0"; s = s.replace("0x", ""); char c = (char)Integer.parseInt(s, 16);
------解决方案--------------------
路过............
------解决方案--------------------
补充一下
public class TempTest { /** * @param args */ public static void main(String[] args) { String str = "0xA0"; String rtStr = bytesToHexString(str.getBytes()); int i = Integer.valueOf(rtStr); char ch = (char) i;// 将int类型转换成字符 System.out.println(ch);// 输出 } /** */ /** * 把字节数组转换成16进制字符串 * * @param bArray * @return */ public static final String bytesToHexString(byte[] bArray) { StringBuffer sb = new StringBuffer(bArray.length); String sTemp; for (int i = 0; i < bArray.length; i++) { sTemp = Integer.toHexString(0xFF & bArray[i]); if (sTemp.length() < 2) sb.append(0); sb.append(sTemp.toUpperCase()); } return sb.toString(); } }
------解决方案--------------------
------解决方案--------------------
估计只能用char数组来装了!
------解决方案--------------------
public class Test2 { public static void main(String[] args) { char c = hex2Char("0x40")[0]; System.out.println(c); } public static char[] hex2Char(String hexString) { if(!hexString.matches("0x[0-9a-fA-F]+")) { throw new IllegalArgumentException("参数应是一个以 0x 开头的十六进制字符串"); } int codePoint = Integer.parseInt(hexString.substring(2), 16); if((codePoint < 0) || (codePoint > Character.MAX_CODE_POINT)) { throw new IllegalArgumentException(hexString + " 所能表示的字符范围溢出"); } return Character.toChars(codePoint); } }
------解决方案--------------------