Java与C#通信之byte[]转short问题

public short getMsgByteLen(DataInputStream dis) {

  byte[] lens = new byte[2];

  try{

    dis.read(lens);

  } catch(IOException e) {

    e.printStackTrace();

  }

  //如果是和java通信

  return (short)((lens[0] << 8) + lens[1]);

  //如果是和C#通信

  return (short)((lens[1] << 8) + lens[0]);

}

posted @ 2014-03-05 22:36  bingoogolapple  阅读(985)  评论(0)    收藏  举报