2010-01-11 63 views
1
private byte[] decode_text(byte[] image) 
{ 
    int length = 0; 
    int offset = 32; 
    for(int i=0; i<32; ++i) 
    { 
     length = (length << 1) | (image[i] & 1); 
    } 
    byte[] result = new byte[length]; 
    for(int b=0; b<result.length; ++b) 
    { 
     for(int i=0; i<8; ++i, ++offset) 
      { 
      /* I'm getting error at the following line */ 
      result = (byte)((result << 1) | (image[offset] & 1)); 
      } 
     } 
    return result; 
} 

错误是不兼容的数据类型...所需的byte [],发现字节..........Java的错误: “不兼容数据类型”

回答

1

不能位移位的result变量因为它是一个字节数组。

1

你可能想:

result[b] = (byte)((result[b] << 1) | (image[offset] & 1)); 
1

你也不能指定单个bytebyte - 阵列。

0

您铸造所有这些操作

((result << 1) | (image[offset] & 1)); 

的结果(byte)并将其分配给byte[]

你可以宣布一个新字节变量,你对这个变量的操作,然后做

result[i] = myNewByteVariable; 
0

你可能想这样做

byte[] result = new byte[length]; 
    for(int b=0; b<result.length; ++b) 
    { 
     byte value = 0; 
     for(int i=0; i<8; ++i, ++offset) 
     { 
      /* I'm getting error at the following line */ 
      value = (byte) ((value << 1) | (image[offset] & 1)); 
     } 
     result[b] = value; 
    }