62,614
社区成员
发帖
与我相关
我的任务
分享
System.err.println((char)(((buf[0] & 0xff) << 8) | (buf[1] & 0xff)));
输出的是字符,因为你把它转为char了System.err.println((((buf[0] & 0xff) << 8) | (buf[1] & 0xff)));
System.err.println((char)(((buf[0] & 0xff) << 8) | (buf[1] & 0xff)));
System.err.println((char)(((buf[0] & 0xff) << 8) | (buf[1] & 0xff)));
public static byte[] charToByte(char ch){
int temp=(int)ch;
byte[] b=new byte[2];
for (int i=b.length-1;i>-1;i--){
b[i] = new Integer(temp&0xff).byteValue(); //将最高位保存在最低位
temp = temp >> 8; //向右移8位
}
return b;
}