Android Utililty Methods Int to Byte Array Convert

List of utility methods to do Int to Byte Array Convert

Description

The list of methods to do Int to Byte Array Convert are organized into topic(s).

Method

byte[]intToBytes(int number)
int To Bytes
return new byte[] { (byte) ((number >> 24) & 0xFF),
        (byte) ((number >> 16) & 0xFF),
        (byte) ((number >> 8) & 0xFF), (byte) (number & 0xFF) };
byte[]intToBytes(int x)
int To Bytes
int_buffer = ByteBuffer.allocate(4);
int_buffer.putInt(x);
return subByte(int_buffer.array(), -2);
byte[]toBytes(int value)
to Bytes
byte[] dest = new byte[4];
toBytes(value, dest, 0);
return dest;
voidtoBytes(int value, byte[] dest, int destPos)
to Bytes
for (int i = 0; i < 4; i++) {
    dest[i + destPos] = (byte) (value >> ((7 - i) * 8));
byte[]getBytes(int data)
get Bytes
byte[] bytes = new byte[4];
bytes[0] = (byte) (data & 0xff);
bytes[1] = (byte) ((data & 0xff00) >> 8);
bytes[2] = (byte) ((data & 0xff0000) >> 16);
bytes[3] = (byte) ((data & 0xff000000) >> 24);
return bytes;
voidputInt(byte[] bb, int x, int index)
put Int
bb[index + 0] = (byte) (x >> 24);
bb[index + 1] = (byte) (x >> 16);
bb[index + 2] = (byte) (x >> 8);
bb[index + 3] = (byte) (x >> 0);
voidputInt(byte[] bb, int x, int index)
put Int
bb[index + 3] = (byte) (x >> 24);
bb[index + 2] = (byte) (x >> 16);
bb[index + 1] = (byte) (x >> 8);
bb[index + 0] = (byte) (x >> 0);
byte[]int2bytes(int val)
intbytes
byte[] data = new byte[4];
data[0] = (byte) (val & 0xFF);
data[1] = (byte) (val >> 8 & 0xFF);
data[2] = (byte) (val >> 16 & 0xFF);
data[3] = (byte) (val >> 24 & 0xFF);
return data;
byte[]IntToByte(int i)
Int To Byte
byte[] result = new byte[4];
result[0] = (byte) ((i >> 24) & 0xFF);
result[1] = (byte) ((i >> 16) & 0xFF);
result[2] = (byte) ((i >> 8) & 0xFF);
result[3] = (byte) (i & 0xFF);
return result;
byte[]uInt16ToBytesBI(int value)
u Int To Bytes BI
byte b[] = new byte[2];
uInt16ToBytesBI(value, b, 0);
return b;