Here you can find the source of getShort(byte[] buf, boolean bigEndian)
Parameter | Description |
---|---|
buf | the source byte array |
bigEndian | true if big endian, false if little endian |
public static final short getShort(byte[] buf, boolean bigEndian)
//package com.java2s; public class Main { /**// w ww .j a v a2 s . com * Convert byte sequence into java short from first 2 bytes * * @param buf the source byte array * @param bigEndian true if big endian, false if little endian * @return short the java short */ public static final short getShort(byte[] buf, boolean bigEndian) { return getShort(buf, 0, bigEndian); } /** * Convert byte sequence into java short. * * @param buf the source byte array * @param pos the position of array to convert from * @param bigEndian true if big endian, false if little endian * @return short the java short */ public static final short getShort(byte[] buf, int pos, boolean bigEndian) { if (bigEndian) { return (short) ((buf[pos] << 8) | (buf[pos + 1] & 0xff)); } else { return (short) ((buf[pos + 1] << 8) | (buf[pos] & 0xff)); } } }