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[]IntToBytes4(int i)
Int To Bytes
byte abyte0[] = new byte[4];
abyte0[3] = (byte) (0xff & i);
abyte0[2] = (byte) ((0xff00 & i) >> 8);
abyte0[1] = (byte) ((0xff0000 & i) >> 16);
abyte0[0] = (byte) ((0xff000000 & i) >> 24);
return abyte0;
voidintToBytesBE(int value, byte[] buffer)
int To Bytes BE
intToBytesBE(value, buffer, 0, buffer.length);
byte[]intToBytesBigend(int value)
int To Bytes Bigend
byte[] src = new byte[4];
src[0] = (byte) ((value >> 24) & 0xFF);
src[1] = (byte) ((value >> 16) & 0xFF);
src[2] = (byte) ((value >> 8) & 0xFF);
src[3] = (byte) (value & 0xFF);
return src;
byte[]intToBytesBigEndian(int n)
int to byte array (big endian)
byte[] buf = new byte[4];
buf[0] = (byte) ((0xff000000 & n) >> 24);
buf[1] = (byte) ((0xff0000 & n) >> 16);
buf[2] = (byte) ((0xff00 & n) >> 8);
buf[3] = (byte) (0xff & n);
return buf;
byte[]IntToBytesLE(final long val)
Int To Bytes LE
byte[] buf = new byte[4];
for (int i = 0; i < 4; i++) {
    buf[i] = (byte) (val >>> (8 * i));
return buf;
byte[]intToBytesLE(int i, byte[] bytes, int off)
int To Bytes LE
bytes[off + 3] = (byte) (i >> 24);
bytes[off + 2] = (byte) (i >> 16);
bytes[off + 1] = (byte) (i >> 8);
bytes[off] = (byte) i;
return bytes;
voidintToBytesLE(int value, byte[] buffer, int offset, int length)
Converts an int to a little-endian sequence of bytes of the specified length.
int endOffset = offset + length;
for (int i = offset; i < endOffset; ++i) {
    buffer[i] = (byte) value;
    value >>>= 8;
voidintToBytesLittleEndian(final int i, final byte[] dest, final int offset)
Single int into byte array
dest[offset] = (byte) (i & 0xFF);
dest[offset + 1] = (byte) ((i >> 8) & 0xFF);
dest[offset + 2] = (byte) ((i >> 16) & 0xFF);
dest[offset + 3] = (byte) ((i >> 24) & 0xFF);
byte[]intToBytesNoLeadZeroes(int val)
Converts a int value into a byte array.
if (val == 0) {
    return EMPTY_BYTE_ARRAY;
int lenght = 0;
int tmpVal = val;
while (tmpVal != 0) {
    tmpVal = tmpVal >>> 8;
    ++lenght;
...
byte[]intToBytesSizeOne(int integer)
int To Bytes Size One
byte[] bytes = new byte[1];
bytes[0] = (byte) (integer);
return bytes;