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 i)
converts an int to an array of bytes.
byte[] ret = new byte[4];
ret[0] = (byte) ((i & 0xff000000) >> 24);
ret[1] = (byte) ((i & 0x00ff0000) >> 16);
ret[2] = (byte) ((i & 0x0000ff00) >> 8);
ret[3] = (byte) (i & 0x000000ff);
return ret;
byte[]intToByteArray(int input)
Utility method for converting a int into a byte[]
byte[] output = new byte[4];
intToByteArray(input, output, 0);
return output;
byte[]intToByteArray(int integer)
int To Byte Array
return new byte[] { (byte) ((integer & 0xFF000000) >> 24), (byte) ((integer & 0x00FF0000) >> 16),
        (byte) ((integer & 0x0000FF00) >> 8), (byte) ((integer & 0x000000FF)) };
byte[]intToByteArray(int integer)
Converts an integer into an unsigned 4-byte array.
byte[] intBytes = new byte[4];
intBytes[0] = (byte) ((integer & 0xff000000) >>> 24);
intBytes[1] = (byte) ((integer & 0x00ff0000) >>> 16);
intBytes[2] = (byte) ((integer & 0x0000ff00) >>> 8);
intBytes[3] = (byte) ((integer & 0x000000ff));
return intBytes;
byte[]intToByteArray(int piValueToConvert, boolean pbBigEndian)
Converts an int value to a byte array.
byte[] aRetVal = new byte[4];
byte iLowest;
byte iLow;
byte iMid;
byte iHigh;
iLowest = (byte) (piValueToConvert & 0xFF);
iLow = (byte) ((piValueToConvert >> 8) & 0xFF);
iMid = (byte) ((piValueToConvert >> 16) & 0xFF);
...
voidintToByteArray(int pSrc, byte[] pDst, int pOffset)
int To Byte Array
pDst[pOffset] = (byte) (pSrc >>> 24);
pDst[pOffset + 1] = (byte) (pSrc >>> 16);
pDst[pOffset + 2] = (byte) (pSrc >>> 8);
pDst[pOffset + 3] = (byte) pSrc;
byte[]intToByteArray(int source)
Converts the bypassed int value to a byte array.
byte[] result = new byte[4];
for (int i = 0; i < 4; ++i) {
    result[3 - i] = (byte) ((source & (0xff << (i << 3))) >>> (i << 3));
return result;
voidIntToByteArray(int val, byte[] buf, int offset)
Write integer into buf[offset]...buf[offset+3]
buf[0 + offset] = (byte) ((val >> 24) & 255);
buf[1 + offset] = (byte) ((val >> 16) & 255);
buf[2 + offset] = (byte) ((val >> 8) & 255);
buf[3 + offset] = (byte) (val & 255);
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)
int To Byte Array
try {
    return new byte[] { (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8),
            (byte) (value) };
} catch (NullPointerException npe) {
    return null;