List of utility methods to do Array Unpack
StringBuffer | unpack(byte[] array) unpack int len = array.length; int length = len << 1; StringBuffer buf = new StringBuffer(length); buf.setLength(length); for (int i = 0, j = 0; i < len; ++i) { byte by = array[i]; byte hi = (byte) ((by & 0xF0) >> 4); byte lo = (byte) (by & 0x0F); ... |
String | unpack(byte[] bytes) unpack if (bytes.length == 0) return ""; int len = bytes[0] & 0xFF, off = 1; StringBuilder builder = new StringBuilder(); int key = 0; for (;;) { byte b = bytes[off++]; for (int mask = 0x80; mask != 0; mask >>= 1) { ... |
double[][] | unpack(double[] packed, int width, int height, int outputIndex) Returns a new array that is the result of unpacking the given 1D array into a 2D array, row-first. double[][] unpacked = new double[height][width]; return unpack(packed, unpacked, outputIndex); |
int | unpack(int[] sourcearray, int arraypos, int[] data, int datapos, int num, int b) unpack if (b > 16) { System.arraycopy(sourcearray, arraypos, data, 0, num); return num + arraypos; final int mask = (1 << b) - 1; int inwordpointer = 0; for (int k = 0; k < num; ++k) { data[k + datapos] = ((sourcearray[arraypos] >>> inwordpointer) & mask); ... |
byte[] | unpackBCD(byte[] source) Unpack the binary-coded decimal. byte[] ret = new byte[source.length * 2]; int index = 0; for (byte aSource : source) { ret[index + 1] = (byte) (aSource & 0x0F); ret[index] = (byte) ((aSource >> 4) & 0x0F); index += 2; return ret; ... |
boolean[] | unpackDie(byte[] bytes) unpack Die boolean[] bits = new boolean[bytes.length * 8]; int mask = 1; for (int i = 0; i < bits.length; i++) { int dataIndex = i / 8; byte dataByte = bytes[dataIndex]; int bitIndex = i % 8; bits[i] = (dataByte & ((byte) (mask << bitIndex))) != 0; return bits; |
byte[] | UnpackFloat(byte[] bytes, float value) Unpacks a floating-point value into four bytes. int intBits = Float.floatToRawIntBits(value); return UnpackLittle32(bytes, intBits); |
void | UnpackFloatBuffer(byte[] buffer, long bytes_read, long num_loaded, float[] list) Get the float values stored in the input file buffer and put the values into the proper positions in the list[] array. int index = (int) (num_loaded); for (int i = 0; i < bytes_read; i += 4) list[index++] = getFloat_32(buffer, i); |
int | unpackInt(byte[] data, int offset) Unpack an int stored as MSB first in a byte array int value = 0; value |= (data[offset] << 24) & 0xff000000; value |= (data[offset + 1] << 16) & 0x00ff0000; value |= (data[offset + 2] << 8) & 0x0000ff00; value |= data[offset + 3] & 0x000000ff; return value; |
int | unpackIntegerByWidth(int len, byte[] buf, int offset) Unpack a big endian integer, of a given length, from a byte array. if (len == 1) { return buf[offset]; } else if (len == 2) { return (buf[offset] << 24 | (buf[offset + 1] & 0xFF) << 16) >> 16; } else if (len == 3) { return (buf[offset] << 24 | (buf[offset + 1] & 0xFF) << 16 | (buf[offset + 2] & 0xFF) << 8) >> 8; } else if (len == 4) { return buf[offset] << 24 | (buf[offset + 1] & 0xFF) << 16 | (buf[offset + 2] & 0xFF) << 8 ... |