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[]intToByteArray(int value)
Convert the specified int to a 4 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[]intToByteArray(int value)
int To Byte Array
return new byte[] { (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value };
byte[]intToByteArray(int value)
Converts an integer value to a byte array.
byte[] bytes = new byte[INT_BYTE_ARRAY_LENGTH];
bytes[0] = (byte) (value >> 24);
bytes[1] = (byte) (value >> 16);
bytes[2] = (byte) (value >> 8);
bytes[3] = (byte) (value);
return bytes;
byte[]intToByteArray(int value)
int To Byte Array
return intToBytes(value);
byte[]intToByteArray(int value)
int To Byte Array
byte[] result = new byte[4];
result[3] = (byte) (value >>> 24);
result[2] = (byte) (value >>> 16);
result[1] = (byte) (value >>> 8);
result[0] = (byte) value;
return result;
byte[]intToByteArray(int value)
int To Byte Array
byte[] bytes = new byte[4];
intToByteArray(bytes, 0, value);
return bytes;
byte[]intToByteArray(int value)
Converts the given integer value into a byte array.
return new byte[] { (byte) ((value >>> 24) & 0xFF), (byte) ((value >>> 16) & 0xFF),
        (byte) ((value >>> 8) & 0xFF), (byte) (value & 0xFF) };
voidintToByteArray(int value, byte[] buffer, int offset)
Convert the provided into into a byte[] and write the values into the given buffer starting at the provided offset (this will take up 4 bytes!)
buffer[offset] = (byte) (value >>> 24);
buffer[offset + 1] = (byte) (value >>> 16);
buffer[offset + 2] = (byte) (value >>> 8);
buffer[offset + 3] = (byte) (value);
byte[]intToByteArray(int value, byte[] data, int offset)
int To Byte Array
if (data == null)
    data = new byte[4];
int temp = Math.abs(value);
for (int i = 0; i < 4; i++) {
    data[offset + i] = (byte) (temp % 256);
    temp = temp / 256;
    if (i == 0 && value < 0)
        data[offset] = (byte) (~data[offset] + 1);
...
voidintToByteArray(int value, byte[] dest)
int To Byte Array
int lastIndex = dest.length - 1;
for (int i = lastIndex; i >= 0; i--) {
    dest[i] = (byte) (value & 0xff);
    value = value >> 8;