readInt() or readDouble()and you can combine 4 byte into one int by yourself.

解决方案 »

  1.   

    please write code to me!
      

  2.   

    怎么会这样,你是怎么传的值。
    如果值正确的话 if parameter < 0 then parameter = parameter * -1;
      

  3.   

    是这样子:
    服务器传过来一个数据包,前8个为数值
    而前四个为长度,后四个为类型,也是用整型值表示的。
    这两个数据都是用四位表示的。
    现在我接收到的数据如下:
    0A 00 00 00 c8 00 00 00
    服务器是C++写的。数据很好表示。
    但是在java这一端就有问题,因为后四个字节的值大于了127,就变成了负数。c8是十进制的200,而在java中变成了-56,
    如何才能转成正数,200呢?
      

  4.   

    public int myReadInt(InputStream is) throws IOException {
            int result = 0;
            int tmp = is.read();
            result = (tmp & 0xff) << 24;
            tmp = is.read();
            result += (tmp & 0xff) << 16;
            tmp = is.read();
            result += (tmp & 0xff) << 8;
            tmp = is.read();
            result += (tmp & 0xff);
            return result;
        }
      

  5.   

    问题的根源是Java没有C里面的unsigned类型,解决办法是参考DataInputStream的原码写,其实就是楼上老大贴的代码:)