Android Utililty Methods Byte Array Convert From

List of utility methods to do Byte Array Convert From

Description

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

Method

voidtoByteArray(float val, byte[] b, int pos)
to Byte Array
try {
    ByteBuffer bb = ByteBuffer.allocate(4);
    FloatBuffer fb = bb.asFloatBuffer();
    fb.put(val);
    for (int i = 0; i < 4; i++) {
        b[pos + i] = bb.get(i);
} catch (Exception e) {
...
byte[]toByteArray(float[] array)
Convert an array of floats to a byte[] using native endian order.
return toByteArray(array, Float.SIZE);
byte[]toByteArray(int[] array)
Convert an array of ints to a byte[] using native endian order.
return toByteArray(array, Integer.SIZE);
byte[]toByteArray(long[] array)
Convert an array of longs to a byte[] using native endian order.
return toByteArray(array, Long.SIZE);
voidtoByteArray(short val, byte[] b, int pos)
to Byte Array
assert (pos + 2 <= b.length);
b[pos] = (byte) (val & 0x00FF);
b[pos + 1] = (byte) ((val & 0xFF00) >> 8);
byte[]toByteArray(short[] array)
Convert an array of shorts to a byte[] using native endian order.
return toByteArray(array, Short.SIZE);
byte[]toByteArrayFromByteWrapperArray(Byte[] B)
to Byte Array From Byte Wrapper Array
if (B == null) {
    return null;
byte[] b = new byte[B.length];
for (int i = 0; i < B.length; i++) {
    b[i] = B[i].byteValue();
return b;
...
byte[]convertIntArrayToByteArray(int[] intArray)
Converts an int array to a byte array.
if (intArray == null)
    return null;
byte[] bytes = new byte[intArray.length * 4];
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
for (int v : intArray) {
    byteBuffer.putInt(v);
return bytes;
...
byte[]shortToByteArray(short value)
short To Byte Array
return new byte[] { (byte) (value >>> 8), (byte) value };
byte[]convertLongArrayToByteArray(long[] longArray)
Converts a long array to a byte array.
if (longArray == null)
    return null;
byte[] bytes = new byte[longArray.length * 8];
ByteBuffer byteBuffer = ByteBuffer.wrap(bytes);
for (long v : longArray) {
    byteBuffer.putLong(v);
return bytes;
...