Here you can find the source of toShort(byte[] bytes, boolean bigEndian)
static public short toShort(byte[] bytes, boolean bigEndian)
//package com.java2s; /*/* w w w . j av a 2 s .co m*/ * Copyright 1999-2004 Carnegie Mellon University. * Portions Copyright 2002-2004 Sun Microsystems, Inc. * Portions Copyright 2002-2004 Mitsubishi Electric Research Laboratories. * All Rights Reserved. Use is subject to license terms. * * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL * WARRANTIES. * */ public class Main { /** Converts a byte array to a signed short value. */ static public short toShort(byte[] bytes, boolean bigEndian) { if (bytes.length == 1) { return bytes[0]; } else if (bigEndian) { return (short) ((bytes[0] << 8) | (0xff & bytes[1])); } else { return (short) ((bytes[1] << 8) | (0xff & bytes[0])); } } }