Here you can find the source of byteToShort(byte[] byteData, boolean writeLittleEndian)
Parameter | Description |
---|---|
byteData | The byte array. |
writeLittleEndian | If true data is handled as little endian, else as big endian |
public static short[] byteToShort(byte[] byteData, boolean writeLittleEndian)
//package com.java2s; //License from project: Open Source License public class Main { /**/* w ww. j a v a2s .co m*/ * Function converts a byte array to a short array. * * @param byteData * The byte array. * @param writeLittleEndian * If true data is handled as little endian, else as big endian * @return The short array. */ public static short[] byteToShort(byte[] byteData, boolean writeLittleEndian) { short[] data = new short[byteData.length / 2]; int size = data.length; byte lb, hb; if (writeLittleEndian) { for (int i = 0; i < size; i++) { lb = byteData[i * 2]; hb = byteData[i * 2 + 1]; data[i] = (short) (((short) hb << 8) | lb & 0xff); } } else { for (int i = 0; i < size; i++) { lb = byteData[i * 2]; hb = byteData[i * 2 + 1]; data[i] = (short) (((short) lb << 8) | hb & 0xff); } } return data; } }