Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bitwise XOR operation in Java

I am facing this error while executing my program.

"bad operand types for binary operator '^' first type:int second type:int[]"

int temp1;
     for(int m = 1;m<height;m++)
     {
         temp1 = 2*m-1;
         for(int n = 0;n<width;n++)
         {
             r[temp1][n] = r[temp1][n]^Kc[n];
         }
     }

This will help me alot, Thanks.

like image 684
user3364490 Avatar asked Jul 16 '26 02:07

user3364490


2 Answers

You can apply the^ operator on two ints, not on an int and an int array.

Based on the error message, Kc[n] is an array of int.

You can apply the operator on two ints :

r[temp1][n] = r[temp1][n]^Kc[temp1][n];

I have no idea if the indices make sense (since I don't know the dimensions of the 2 arrays), so you might have to change them.

like image 61
Eran Avatar answered Jul 17 '26 16:07

Eran


The error message is saying that Kc[n] is an array of ints. It needs to be an int.

If you mean for Kc[n] to be an integer, you've miss-declared it.

like image 37
Joel Avatar answered Jul 17 '26 16:07

Joel