Android Utililty Methods Big Endian Convert

List of utility methods to do Big Endian Convert

Description

The list of methods to do Big Endian Convert are organized into topic(s).

Method

voidtoggleIntEndian(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);
...
voidtoggleLongEndian(byte[] b)
toggle Long Endian
if (b != null)
    toggleLongEndian(b, 0, b.length);
voidtoggleLongEndian(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);
...
voidtoggleShortEndian(byte[] b)
toggle Short Endian
if (b != null)
    toggleShortEndian(b, 0, b.length);
voidtoggleShortEndian(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);
...
intgetInt(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));
shortgetShort(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));
intswitchEndian(int i)
switch Endian
return ((i & 0xff000000) >>> 24) | ((i & 0x00ff0000) >>> 8)
        | ((i & 0x0000ff00) << 8) | ((i & 0x000000ff) << 24);
longswitchEndian(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);
shortswitchEndian(short i)
switch Endian
return (short) (((i & 0xff00) >>> 8) | ((i & 0x00ff) << 8));