I need to flip a 1-D 64-element array of shorts (I can switch to ints if it's easier, but I assume the same processes will work for either) on it's head in Java. I represent it here as a square table for ease of understanding, since the actual problem is on a chessboard.
For example:
short[] example = new short[]
{
1, 2, 3,
4, 5, 6,
7, 8, 9
};
would become:
7 8 9
4 5 6
1 2 3
Please note that this is NOT the same as reversing the array (every answerer to similar questions I have found has made this mistake, hence my having to ask!). Reversing the array would give:
9 8 7
6 5 4
3 2 1
Apologies if I've missed any important info, any help is appreciated!
EDIT: The array is 1D and contains 64 elements, so short[64], and the reversed array is separate to the original. As far as what I've tried, I'm just struggling to wrap my head around it. I know how to reverse the array, but that's not what I'm after, and I had originally tried to reverse the index using:
byte index = (byte)(((byte)(position + 56)) - (byte)((byte)(position / 8) * 16));
Which is a code snippet I found on Chessbin, but this returns incorrect values and gives IndexOutOfBounds errors. In hindsight it's not clear to me if that code is meant to flip the index or reverse it. Since maths is not my strong suit, I tried to work around it with separate arrays.