Java Utililty Methods Integer to Byte Array

List of utility methods to do Integer to Byte Array

Description

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

Method

byte[]intToBytes(int i)
int To Bytes
byte[] bytes = new byte[4];
bytes[3] = (byte) (i & MASK_TO_BYTE);
i >>= NUMBER_OF_BITS_IN_A_BYTE;
bytes[2] = (byte) (i & MASK_TO_BYTE);
i >>= NUMBER_OF_BITS_IN_A_BYTE;
bytes[1] = (byte) (i & MASK_TO_BYTE);
i >>= NUMBER_OF_BITS_IN_A_BYTE;
bytes[0] = (byte) (i & MASK_TO_BYTE);
...
byte[]intToBytes(int i)
int To Bytes
boolean neg = false;
int digs = 1;
if (i < 0) {
    digs++;
    neg = true;
    i = -i;
int base10 = 10;
...
byte[]intToBytes(int i)
Spilts an int into 4 bytes
return new byte[] { (byte) (i >> 24), (byte) (i >> 16), (byte) (i >> 8), (byte) i };
byte[]intToBytes(int i)
Converts primitive int type to byte array.
return toBytes(i, new byte[4], 0, 4);
byte[]intToBytes(int i)
int To Bytes
byte[] intBytes = new byte[4];
intBytes[0] = (byte) (i >> 24);
intBytes[1] = (byte) (i >> 16);
intBytes[2] = (byte) (i >> 8);
intBytes[3] = (byte) (i >> 0);
return intBytes;
byte[]intToBytes(int i)
This function converts a integer to its corresponding byte array format.
byte[] buffer = new byte[4];
intToBytes(i, buffer, 0);
return buffer;
byte[]IntToBytes(int i)
Int To Bytes
byte abyte0[] = new byte[2];
abyte0[1] = (byte) (0xff & i);
abyte0[0] = (byte) ((0xff00 & i) >> 8);
return abyte0;
voidintToBytes(int i, byte[] data, int[] offset)
Write the bytes representing i into the byte array data, starting at index offset [0], and increment offset [0] by the number of bytes written; if data == null, increment offset [0] by the number of bytes that would have been written otherwise.
if (data != null) {
    for (int j = (offset[0] + SIZE_INT) - 1; j >= offset[0]; --j) {
        data[j] = (byte) i;
        i >>= 8;
offset[0] += SIZE_INT;
byte[]intToBytes(int i_)
Converts an int into a byte array.
byte abInt[] = new byte[4];
abInt[3] = (byte) (i_ & 255);
abInt[2] = (byte) ((i_ >> 8) & 255);
abInt[1] = (byte) ((i_ >> 16) & 255);
abInt[0] = (byte) (i_ >> 24);
return abInt;
byte[]intToBytes(int intValue)
int To Bytes
byte[] b = new byte[4];
for (int i = 0; i < 4; i++) {
    b[i] = (byte) (intValue >> 8 * (3 - i) & 0xFF);
return b;