That is dreadfully convoluted. You don't need the unsignedShortArray and you don't don't need most of the rest of the code. You can extract the most significant byte of the short using the >>> operator to shift it 8 bits right and cast the result to a byte. You can extract the least significant byte just by casting the short to a byte. This means you just need to very simply deal with the bigEndian difference.
Retired horse trader.
Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
The '>>>' operator does a right shift with no sign extension. That is, it shifts what it has to the right, and fills in the left with 0s. The regular right shift will fill in with the sign bit, that is, the bit in the far left position. However, both operators convert the operands to ints (4 byte integers) first, so in your example where you shift a short by 8 bits, there's effectively no difference between '>>' and '>>>' . Going step by step:
1. array[i] is a short (2 byte) integer
2. array[i] >>> 8 shifts the bits from the high order byte to the low order byte, and sets the high order byte to 0 for positives or 0xFF for negatives. (Technically, it's the third byte of the 4-byte int.)
3. (array[i] >>> 8) & (0xff00) 0s out all but the high order byte of the shifted short (i.e., the third byte of the 4 byte int), and thus is either 0 or 0xFF00 for any possible input.
That's probably not what you want. I suggest just getting your converter working with big-endian shorts first, since that's Java's natural ordering. Then try some sample inputs and make sure the conversion is correct. Once you get that working, you can tackle little-endian shorts.