Search code examples
javac++bitwise-or

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.


Solution

  • 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.