Java Utililty Methods Integer to Byte

List of utility methods to do Integer to Byte

Description

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

Method

byte[]intToByte(int number)
int To Byte
byte[] b = new byte[4];
for (int i = 3; i >= 0; i--) {
    b[i] = (byte) (number % 256);
    number >>= 8;
return b;
byte[]intToByte(int number, int byteLength)
int To Byte
byte[] bLocalArr = new byte[byteLength];
for (int i = 0; (i < 4) && (i < byteLength); i++) {
    bLocalArr[i] = (byte) (number >> 8 * i & 0xFF);
return bLocalArr;
intintToByte(int v, byte[] dest)
int To Byte
int destOffset = 0;
dest[destOffset++] = (byte) ((v >> 24) & 0xFF);
dest[destOffset++] = (byte) ((v >> 16) & 0xFF);
dest[destOffset++] = (byte) ((v >> 8) & 0xFF);
dest[destOffset++] = (byte) (v & 0xFF);
return destOffset;
byteintToByte(int value)
Convert integer to a single byte.
byte[] bytes = intToBytes(value, 4);
return bytes[3];
byteintToByte(int value)
This function converts integer to one byte
if ((value > Math.pow(2, 15)) || (value < 0)) {
    throw new Exception("Integer value " + value + " is larger than 2^15");
return (byte) (value & 0xFF);
byte[]intToByte(int[] values)
int To Byte
if (values == null) {
    return null;
byte[] results = new byte[values.length];
for (int i = 0; i < values.length; i++) {
    results[i] = (byte) values[i];
return results;
...
byte[]intToByte4(int number)
Method converting int into byte array.
int tmp_num = number;
byte[] byte4 = new byte[4];
for (int i = byte4.length - 1; i > -1; i--) {
    byte4[i] = (byte) (tmp_num & 0xff);
    tmp_num = tmp_num >> 8;
return byte4;
byte[]intToByteArr(int v)
int To Byte Arr
return new byte[] { (byte) (v >>> 24), (byte) (v >>> 16), (byte) (v >>> 8), (byte) (v) };