Reputation: 11
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;
}
Error is incompatible datatypes...required byte[] and found byte..........
Upvotes: 1
Views: 639
Reputation: 29680
You probably want to do something like
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;
}
Upvotes: 0
Reputation: 20782
You are casting the result of all these operations
((result << 1) | (image[offset] & 1));
to (byte)
and assigning it to byte[]
.
You could declare a new byte variable, do you manipulations on that variable and then do
result[i] = myNewByteVariable;
Upvotes: 0
Reputation: 838226
You probably want:
result[b] = (byte)((result[b] << 1) | (image[offset] & 1));
Upvotes: 1
Reputation: 31428
You can't bit shift the result
variable because it's a byte array.
Upvotes: 1