菜鸟求助~~

yinsuxia 2010-10-13 11:56:28
求高手给我解释一下这几个方法是什么意思
index是个全局变量,初始值为0

public short readShort(byte[] dis)
{
int firstByte = dis[index++];
int secondByte = dis[index++];
return (short)(firstByte & 0xff | secondByte << 8);
}

public byte readByte(byte[] dis)
{
return (byte)(dis[index++] & 0xff);
}

public int readInt(BinaryReader dis)
{

int a = dis.Read();
int b = dis.Read();
int c = dis.Read();
int d = dis.Read();
if ((a | b | c | d) < 0)
throw new Exception();
else
return (d << 24) + (c << 16) + (b << 8) + (a << 0);
}

public char readChar(BinaryReader dis)
{
int a = dis.Read();
int b = dis.Read();
if ((a | b) < 0)
throw new Exception();
else
return (char)((b << 8) + (a << 0));
}

...全文
144 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
yinsuxia 2010-10-14
  • 打赏
  • 举报
回复
顶起来,难道没人能给解释解释??
昵称很不好取 2010-10-13
  • 打赏
  • 举报
回复
把存放在byte数组中的字节序列,转换为小端模式的数值
yinsuxia 2010-10-13
  • 打赏
  • 举报
回复
顶起来,难道没人能给解释解释??
24K純帥 2010-10-13
  • 打赏
  • 举报
回复
介个都是用二进制读取int,short,char
TheSadLove 2010-10-13
  • 打赏
  • 举报
回复
对位运算符不了解 。学习
a619225471 2010-10-13
  • 打赏
  • 举报
回复
学习中

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧