Here you can find the source of toShort(byte[] buf, int pos)
public static short toShort(byte[] buf, int pos)
//package com.java2s; //License from project: Apache License public class Main { public static short toShort(byte[] buf, int pos) { return (short) (toUnsignedByte(buf, pos) << 8 + toUnsignedByte(buf, pos + 1)); }//from w w w .j a v a2 s . c o m public static int toUnsignedByte(byte[] buf, int pos) { int b = buf[pos]; if (b < 0) { b = 256 + b; } return b; } }