为了账号安全,请及时绑定邮箱和手机立即绑定

DataOutputSteam的writeInt为什么要这么实现呢?

DataOutputSteam的writeInt为什么要这么实现呢?

MYYA 2019-03-22 19:19:16
看thingking in java的IO部分时提到了DataOutputSteam, 于是查看了一下源码, 发现DataOutputStream在实现writeLong, writeInt ,writeChar和writeShort都采用了这种方法实现:public final void writeChar(int v) throws IOException {    out.write((v >>> 8) & 0xFF);    out.write((v >>> 0) & 0xFF);    incCount(2);}public final void writeInt(int v) throws IOException {    out.write((v >>> 24) & 0xFF);    out.write((v >>> 16) & 0xFF);    out.write((v >>>  8) & 0xFF);    out.write((v >>>  0) & 0xFF);    incCount(4);}public final void writeLong(long v) throws IOException {    writeBuffer[0] = (byte)(v >>> 56);    writeBuffer[1] = (byte)(v >>> 48);    writeBuffer[2] = (byte)(v >>> 40);    writeBuffer[3] = (byte)(v >>> 32);    writeBuffer[4] = (byte)(v >>> 24);    writeBuffer[5] = (byte)(v >>> 16);    writeBuffer[6] = (byte)(v >>>  8);    writeBuffer[7] = (byte)(v >>>  0);    out.write(writeBuffer, 0, 8);    incCount(8);}我想知道的是为什么要先无符号右移,然后和00ff进行与运算呢?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 680 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信