Here you can find the source of bytesToShort(byte[] buf)
public static short bytesToShort(byte[] buf)
//package com.java2s; //License from project: Apache License public class Main { public static short bytesToShort(byte[] buf) { return (short) (((0xff & buf[0]) << 8) | (0xff & buf[1])); }//from w w w .ja v a 2 s . c om public static short bytesToShort(byte[] buf, int startIdx) { return (short) (((0xff & buf[startIdx]) << 8) | (0xff & buf[startIdx + 1])); } }