Here you can find the source of bytesToShort(byte[] bytes, boolean netOrder)
public static short bytesToShort(byte[] bytes, boolean netOrder)
//package com.java2s; //License from project: Open Source License public class Main { public static short bytesToShort(byte[] bytes, boolean netOrder) { if (bytes == null) { return 0; }//from w w w. j a v a 2s .co m return (netOrder ? (short) ((bytes[0] & 0xFF << 8) | (bytes[1] & 0xFF)) : (short) ((bytes[1] & 0xFF << 8) | (bytes[0] & 0xFF))); } }