List of utility methods to do Big Endian Convert
void | toggleIntEndian(byte[] b, int off, int len) toggle Int Endian if (b == null || len == 0) return; int end = off + len; if (off < 0 || len < 0 || end > b.length) throw new IndexOutOfBoundsException("b.length = " + b.length + ", off = " + off + ", len = " + len); if ((len & 3) != 0) throw new IllegalArgumentException("len = " + len); ... |
void | toggleLongEndian(byte[] b) toggle Long Endian if (b != null)
toggleLongEndian(b, 0, b.length);
|
void | toggleLongEndian(byte[] b, int off, int len) toggle Long Endian if (b == null || len == 0) return; int end = off + len; if (off < 0 || len < 0 || end > b.length) throw new IndexOutOfBoundsException("b.length = " + b.length + ", off = " + off + ", len = " + len); if ((len & 7) != 0) throw new IllegalArgumentException("len = " + len); ... |
void | toggleShortEndian(byte[] b) toggle Short Endian if (b != null)
toggleShortEndian(b, 0, b.length);
|
void | toggleShortEndian(byte[] b, int off, int len) toggle Short Endian if (b == null || len == 0) return; int end = off + len; if (off < 0 || len < 0 || end > b.length) throw new IndexOutOfBoundsException("b.length = " + b.length + ", off = " + off + ", len = " + len); if ((len & 1) != 0) throw new IllegalArgumentException("len = " + len); ... |
int | getInt(byte[] data, int i, boolean bigEndian) get Int if (bigEndian) return ((data[i] << 24) + ((data[i + 1] & 0xff) << 16) + ((data[i + 2] & 0xff) << 8) + (data[i + 3] & 0xff)); else return ((data[i + 3] << 24) + ((data[i + 2] & 0xff) << 16) + ((data[i + 1] & 0xff) << 8) + (data[i] & 0xff)); |
short | getShort(byte[] data, int i, boolean bigEndian) get Short if (bigEndian) return (short) ((data[i] << 8) + (data[i + 1] & 0xff)); else return (short) ((data[i + 1] << 8) + (data[i] & 0xff)); |
int | switchEndian(int i) switch Endian return ((i & 0xff000000) >>> 24) | ((i & 0x00ff0000) >>> 8)
| ((i & 0x0000ff00) << 8) | ((i & 0x000000ff) << 24);
|
long | switchEndian(long l) switch Endian return (l >>> 56) | ((l >>> 40) & 0x0000FF00)
| ((l >>> 24) & 0x00FF0000) | ((l >>> 8) & 0xFF000000L)
| ((l & 0xFF000000L) << 8) | ((l & 0x00FF0000) << 24)
| ((l & 0x0000FF00) << 40) | (l << 56);
|
short | switchEndian(short i) switch Endian return (short) (((i & 0xff00) >>> 8) | ((i & 0x00ff) << 8)); |