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[]splitInt(int value)
split Int
byte[] bytes = new byte[2];
bytes[0] = (byte) value;
bytes[1] = (byte) (value >>> 8);
return bytes;
byteint2Byte(int value)
int Byte
byte b = 0;
b = (byte) (value & 0xFF);
return b;
byte[]int2ByteArray(int value)
int Byte Array
byte[] b = new byte[4];
for (int i = 0; i < 4; i++) {
    int offset = (b.length - 1 - i) * 8;
    b[i] = (byte) ((value >>> offset) & 0xFF);
return b;
byte[]int2ByteArray1(int value)
int Byte Array
byte[] b = new byte[1];
for (int i = 0; i < 1; i++) {
    int offset = (b.length - 1 - i) * 8;
    b[i] = (byte) ((value >>> offset) & 0xFF);
return b;
byteint2ByteArray11(int value)
int Byte Array
byte[] b = new byte[1];
for (int i = 0; i < 1; i++) {
    int offset = (b.length - 1 - i) * 8;
    b[i] = (byte) ((value >>> offset) & 0xFF);
return b[0];
byte[]int2ByteArray3(int value)
int Byte Array
byte[] b = new byte[3];
for (int i = 0; i < 3; i++) {
    int offset = (b.length - 1 - i) * 8;
    b[i] = (byte) ((value >>> offset) & 0xFF);
return b;
byte[]int2byte(int input)
intbyte
byte[] result = new byte[4];
for (int i = 0;; i++) {
    if (i >= 4)
        return result;
    result[i] = (byte) (0xFF & input >> i * 8);
byte[]int2byteWithInvert(int input)
intbyte With Invert
byte[] b = int2byte(input);
int len = b.length;
byte[] rtn = new byte[len];
for (int i = 0; i < len; i++) {
    rtn[i] = b[len - 1 - i];
return rtn;
byte[]int2bytesBE(int val, byte[] b, int off)
intbytes BE
b[off] = (byte) (val >>> 24);
b[off + 1] = (byte) (val >>> 16);
b[off + 2] = (byte) (val >>> 8);
b[off + 3] = (byte) val;
return b;
byte[]int2bytesLE(int val, byte[] b, int off)
intbytes LE
b[off] = (byte) val;
b[off + 1] = (byte) (val >>> 8);
b[off + 2] = (byte) (val >>> 16);
b[off + 3] = (byte) (val >>> 24);
return b;