byte[] bytes = str.getBytes("GBK");
if (bytes.length < 2)
return 0;
return (bytes[0] << 8 & 0xff00) + (bytes[1] & 0xff);
return 后面的算法是怎么回事, 不是太明白谁能解释一下么?? 算法编码
if (bytes.length < 2)
return 0;
return (bytes[0] << 8 & 0xff00) + (bytes[1] & 0xff);
return 后面的算法是怎么回事, 不是太明白谁能解释一下么?? 算法编码
str.getBytes("GBK");的意思返回str在GBK字符编码下的字节数组
那么第二个return 就是把两个8位字节数组转换成一个16位的字符编码
高位变低位
(bytes[0] << 8 & 0xff00) + (bytes[1] & 0xff); 转16位(bytes[1] & 0xff) 这句没什么用, 因为byte本身就占1个字节 8位, 和 0xff安位与 所得结果仍是本身