I need to take an int[][] array and shift bits 0-6 one position to the left, while saving bit 7 and setting bit 0 to the previously saved value of bit 7; for each location [row][col] in the array. I have some code that I feel like is right on the verge of this, but I am missing something and I cannot figure out what:
int[][] temp = someArray;
for(int row = 0; row < someArray.length; ++row)
for(int col = 0; col < someArray [row].length; ++col)
{
int num = someArray[row][j];
int numAtSeven = num & (1 << 7);
num = num << 1; //shift
numAtSeven = numAtSeven >> 7; //move to end
num = num | numAtSeven; //put back in
System.out.println(row + " = " + col);
System.out.println(num);
temp[row][j] = num;
}
System.out.println("out");
someArray = temp;
still ArrayOutOfIndex, produces the following output:
0 = 0
279
0 = 1
324
0 = 1
.
.
.
326 = 1
359
326 = 2
301
326 = 3
.
.
.
329
327 = 499
357
out
java.lang.ArrayIndexOutOfBoundsException: 285
Additionally, I need to take the same array and exchange the bottom 2 bits with the top 2 bits for each [row][col], and I am pretty lost on this portion too. I know that I will need a nested for loop again, and that it will be very similar to, if not a mirror of, the above process but this is really stumping me.
I did search for this first, and found a similar question, but I do not understand that code really either, and it still doesn't answer my first question.
edit: running the code throws a java.lang.ArrayIndexOutOfBoundsException
edit2: updated code to reflect changes