1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > C的无符号数据类型int short byte 转为 Java对应的数据long char short

C的无符号数据类型int short byte 转为 Java对应的数据long char short

时间:2021-03-04 20:05:29

相关推荐

C的无符号数据类型int short byte 转为 Java对应的数据long char short

//从网络中读取C的无符号int,short,byte字节数组,相应转换成java的long,char,shortshort anUnsignedByte = 0;char anUnsignedShort = 0;long anUnsignedInt = 0;int firstByte = 0;int secondByte = 0; int thirdByte = 0; int fourthByte = 0;byte buf[] ="1234567890".getBytes();//如:读网络字节数据int index = 0;firstByte = (0x000000FF & ((int)buf[index]));anUnsignedByte = (short)firstByte; index++;firstByte = (0x000000FF & ((int)buf[index])) ; secondByte = (0x000000FF & ((int)buf[index+1]));index = index+2;anUnsignedShort = (char) (firstByte << 8 | secondByte); firstByte = (0x000000FF & ((int)buf[index])) ; secondByte = (0x000000FF & ((int)buf[index+1])); thirdByte = (0x000000FF & ((int)buf[index+2])); fourthByte = (0x000000FF & ((int)buf[index+3])); index = index+4;anUnsignedInt = ((long) (firstByte << 24 | secondByte << 16| thirdByte << 8 | fourthByte)) & 0xFFFFFFFFL;

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。