Android Utililty Methods Int Bit Shift

List of utility methods to do Int Bit Shift

Description

The list of methods to do Int Bit Shift are organized into topic(s).

Method

intnextPowerOf2(int n)
next Power Of
n -= 1;
n |= n >>> 16;
n |= n >>> 8;
n |= n >>> 4;
n |= n >>> 2;
n |= n >>> 1;
return n + 1;
byte[]toByta(int data)
to Byta
return new byte[] { (byte) ((data >> 24) & 0xff),
        (byte) ((data >> 16) & 0xff), (byte) ((data >> 8) & 0xff),
        (byte) ((data >> 0) & 0xff), };
intflip16(int num)
for switching big/small endian
int tmp = num;
tmp = ((tmp & 0x00FF) << 8) + ((tmp & 0xFF00) >> 8);
return tmp;
intswapBytes(int value)
swap Bytes
int b1 = (value >> 0) & 0xff;
int b2 = (value >> 8) & 0xff;
int b3 = (value >> 16) & 0xff;
int b4 = (value >> 24) & 0xff;
return b1 << 24 | b2 << 16 | b3 << 8 | b4 << 0;
intswap(int x)
swap
return (int) ((swap((short) x) << 16) | (swap((short) (x >> 16)) & 0xffff));