楼主,你仔细想想-54和202的区别就知道了,202是-54的补码形式,java的byte是带符号的,而c中byte是不带符号的,这就是为什么小于128的正数,他们的结果都一样,而大于等于128的就不一样了。

解决方案 »

  1.   

    请问怎么让JAVA的byte[]也是无符号的呢。目的是与C语言的 unsigned char *pImage对应。我实验了以下,但是不行
            byte[] mybyte = bos.toByteArray();
           
            for(int i=0;i<mybyte.length;i++){
             mybyte[i] = mybyte[i] & 0xff;  
            }
      

  2.   

    java都是带符号。如果打印结果一样,可以写个有符号数转无符号的function,不过个人觉得,没啥子意义
      

  3.   


    //无符号的范围0-256
    public static void main(String[] args) throws Exception {
    byte  a = (byte)130;
    System.out.println(a);
    System.out.println(convert(a));

    }

    public static int convert(byte b){
    return 256 + b;
    }