下面直接贴代码1. 将GB2312转化为中文,如BAFAC2DCB2B7→胡萝卜,两个字节合成一个文字 public static String stringToGbk(String string) throws Exception { byte[ ...
下面直接贴代码
1. 将GB2312转化为中文,如BAFAC2DCB2B7→胡萝卜,两个字节合成一个文字
public static String stringToGbk(String string) throws Exception { byte[] bytes = new byte[string.length() / 2]; for (int j = 0; j < bytes.length; j++) { byte high = Byte.parseByte(string.substring(j * 2, j * 2 + 1), 16); byte low = Byte.parseByte(string.substring(j * 2 + 1, j * 2 + 2), 16); bytes[j] = (byte) (high << 4 | low); } String result = new String(bytes, "GBK"); return result; }
原标题:Android与单片机通信常用数据转换方法(汇总)
关键词:Android
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们:
admin#shaoqun.com
(#换成@)。