How can I convert a short
(2 bytes) to a byte array in Java, e.g.
short x = 233;
byte[] ret = new byte[2];
...
it should be something like this. But not sure.
((0xFF << 8) & x) >> 0;
EDIT:
Also you can use:
java.nio.ByteOrder.nativeOrder();
To discover to get whether the native bit order is big or small. In addition the following code is taken from java.io.Bits
which does:
And visa versa.
ret[0] = (byte)(x & 0xff);
ret[1] = (byte)((x >> 8) & 0xff);